nov 1
aside
midterm projects
- grades and comments are up
- generally good work
Continue to practice methodology; please try to follow the rules I've set down:
- docstrings : file, class, function, method
- clear : "Returns ___ given ___ " ; not "how", but "what".
- tests : doctests or other type of debug print ; something to make sure small pieces are behaving as expected
- program in tiny chunks
- think hard about inputs and outputs to things ; the interfaces (API) are where it flies or falters
- many functions without calls or returns should be a "hmmm" signal
- avoiding repetition ; parallel code constructions should be a warning sign
- name constants, variables, functions clearly
go over homework
- discuss your understanding of classes, objects, instances
- volunteers ?
- refactor someone's code ?
this week: Chapter 11
- lots practice with lists
- dictionaries - a new data structure
New syntax: python "dictionary"
passwords = { "guido" : "superman",
"bill" : "bluescreen",
"santa" : "rudolph.the.red" }
print passwords["bill"]
for name in passwords.keys():
print "%s : %s" % (name, passwords[name])
Like lists, but
- no specific order
- strings, not numbers, as "index" subscript.
- sometimes called "hash tables"
- sometimes called "associations"
- ... under any name, a powerful data structure
Look at python docs for dictionary methods; try a few out.
Go over text's example : counting words (see attachments)