lopping over Dictionaries
Tim Hochberg
hochberg at psn.net
Fri Sep 17 13:38:33 EDT 1999
>Is it possible to iterate through list of keys in a Dictionary?
>
>something like this:
>
>tel = {'jack': 4098, 'sape': 4139}
>
>for (name, value) in tel.keys:
> print name, value
Yes, although the spelling is a little different.
for (name, value) in tel.items():
print name, value
Also, tel.keys() returns the keys ('jack', 'sape'), and tel.values() returns
the values (4098, 4139). Note that all of these return their results in
arbitrary order.
-tim
More information about the Python-list
mailing list