# Ensure you are on your master branch git checkout master # Grab the latest release files git fetch release # Reset your repo to the latest release files # !!!: will delete any work you did # (but there should be none) git reset --hard release/master # Push your local changes to your private repo git push origin master
A generic Python file (anything.py) looks like:
Textbook: Python for Informatics
[
http://do1.dr-chuck.com/py4inf/EN-us/book.pdf
]
See chapters 3, 4, and 5. Review of ideas, new syntax.
Today: emphasis on lists, dictionaries
Exercise: http://repl.it/BEmk/3
Python’s implementation of an array:
# Example:
pastas = ['spaghetti', 'macaroni', 'penne']
print pastas[2]
pastas.append('farfalle')
# What happens for these? mess = [ 'you', 8, ['breakfast', 'lunch', 'dinner']] mess[2][0] mess[2][0][4]
a = ['bat', 'cat', 'hat', 'rat', 'vat', 'yacht'] -------------------------------------------------- index: 0 1 2 3 4 5 value: 'bat' 'cat' 'hat' 'rat' 'vat' 'yacht'
index: 'bate' 'gato' 'sombrero' 'rata' 'tina' 'yate' value: 'bat' 'cat' 'hat' 'rat' 'vat' 'yacht'
What if we wanted to generalize the pairing to indices of any type?
index: 656565656 | 656787787 value: 'Bert' | 'Ernie'
UIN2name = {656565656:'Bert', 656787787:'Ernie'}
UIN2name[656123123] = 'Cookie' #adds to the dictionary
print UIN2name
print UIN2name[656565656]
[
{
"new": "res/packers2.jpg",
"orig": "res/ssfans.jpg"
}
]
import json
orig_name = "packerfy2.jpg"
new_name = "ssfans.jpg"
outData = [{'orig': 'res/' + orig_name,
'new': 'res/' + new_name}]
f = open('res/data.json', 'w')
f.write(json.dumps(outData,indent=4))
What does json.dumps() do?
# Challenge 1
[
{
"lunch": "JJ",
"breakfast": "eggs",
"dinner": "soup"
},
{
"lunch": "salad",
"breakfast": "toast",
"dinner": "pizza"
}
]
# Challenge 2
{
data: [
{
"lunch": "JJ",
"breakfast": "eggs",
"dinner": "soup"
},
{
"lunch": "salad",
"breakfast": "toast",
"dinner": "pizza"
}
]
}
{
"data":[
{
"inputs": {
"left": "kitty",
"right": "puppy",
},
"result": "catdog",
}
]
}
Come to class EVERY TIME
Bring your laptop EVERY TIME