[Tutor] Counting words [reference documentation on dictionaries]
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Thu, 4 Apr 2002 14:38:31 -0800 (PST)
> occurences[word] = occurences.get(word,0)+1
Sean showed that this was equivalent to looking up the 'word' in
'occurences'. If the 'word' actually isn't in there yet, it uses '0' as a
default value.
There's a little more detail about this here:
http://www.python.org/doc/lib/typesmapping.html
though it is a bit sparse. dict.get() is a pretty useful function, and is
there for our convenience.
Good luck to you!