oct 30
- power failure - assignment due today - tomorrow is fine
- discuss homework
- chapter 11 : data collections
# lists
list = [ 'zero', 'one', 'two', 'three', 'four' ]
print list[0] # a single element
print list + ['five', 'six'] # concatenation
print list * 2 # repitition
print len(list) # length
print list[1:2] # slice
print list[:2] # slice from beginning
print list[2:] # slice to end
for word in list: # iteration
print word
if 'two' in list: # membership check
print 'two is in list'
# most of these modify the list; they don't return a new one.
list.append('six') # add something to end of list
list.sort() # order list (in place)
list.reverse() # reverse list (in place)
list.index('one') # return index of where 'one' is
list.insert(3, 'SURPRISE') # insert into list
list.remove('SURPRISE') # remove (first) 'SURPRISE' in list
list.pop(i) # remove ith elelment, and return it
Dictionaries
dict = { 'jim' : 48,
'ian' : 17,
}
print dict['jim']
print dict.keys()