Dictionary as non-iterable object?
Rob Liebscher
rliebsch at cogsci.ucsd.edu
Mon Mar 18 19:01:46 EST 2002
Hi,
My apologies for the simplicity of this question, and if it's been
discussed before. (I'm very new to Python.) The deal is this: using
the IDLE interpreter (directly from www.python.org), I can do the
following:
>>> D = {(4, 6): 13, (4, 3): 12, (5, 2): 11, (2, 5): 8, (1, 2): 9}
>>> for x,y in D:
print D[(x,y)]
13
12
11
8
9
10
>>>
Fine, right? Unfortunately, ActiveState's latest version does not
allow me to do this, saying that I can't iterate over a dictionary's
keys. This happens regardless of how many vars I use: for x, for x,y,
and for x,y,z all complain. (IDLE complains on the first and third
because of a tuple unpack of the wrong size.)
Any ideas? I just want to be able to iterate over all entries in a
dictionary that has 2-tuples as keys, as in the above, so a method to
do this would be a satisfactory answer. Thanks.
More information about the Python-list
mailing list