LPTHW – Lesson 36, 37, 38, 39
Lessons 36 and 37 were mostly review, so nothing too interesting there, but I do plan to periodically return to the keyword lists on p122 and the Python docs in general to ensure that I retain these keywords. Also, I skipped the homework assignments for these two lessons (create a game, read some code) as I plan to do both on a large scale after I’m finished with this book.
Lesson 38 covered lists and string manipulation. It introduced .split(‘ ‘) to split a string into a list and ‘ ‘.join() to reverse the process.
Lesson 39 was a critical one – it introduced dictionaries. Specifically, it covered:
The syntax to add a new item to a dictionary
cities[‘OR’] = ‘Portland’
How to iterate over a dictionary
for state, abbrev in states.items():
How to access one item in a dictionary
state = states.get(‘Texas’, None)
How to check if that ‘get’ retrieved anything useful
if not state:
print “Sorry, no Texas”
Another way to do the same thing:
city = cities.get(‘TX’, ‘Does Not Exist’)
It also introduced collections.OrderedDict if you need a dictionary that retains its order.
Finally, I found (what I think is) a really clear explanation of iterators and generators for a beginner: https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do