Help with dictionary, please
rbl at hal.cwru.edu
rbl at hal.cwru.edu
Fri Aug 6 08:21:27 EDT 1999
I'm rapidly trying to learn Python and despite reading the documentation
and the "Learning Python" book, I can't figure out how to do the following:
- I want to have a 2-dimensional array of word counts, indexed by
a pair of words. I.e. dict[word1,word2]
- In C, I'd just create a 2-dimensional array of integers and increment
as required, but would have to hash the words into integer indices.
- I tried the following in Python:
dict = {}
prev1 = ''
prev2 = ''
[snip]
if prev1 != '' and prev2 != '':
key = (prev2,prev1)
dict[key] = dict[key] + 1
and got this error:
File "Metro:Python 1.5.1:learn2.py", line 34
dict[key] = dict[key] + 1
^
SyntaxError: invalid token
I'm obviously missing something here!
Any guidance greatly appreciated!
Thank you,
Rob Lake
rbl at hal.cwru.edu
More information about the Python-list
mailing list