lopping over Dictionaries

Jeff jam at quark.emich.edu
Fri Sep 17 14:45:01 EDT 1999


On Fri, Sep 17, 1999 at 03:07:18PM -0300, Kevin Howe wrote:
> 
> 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
> 
> 
> Thanks
> 

yes, it is.

[~] [2:41pm] [jam at toast-pts/3] % python
Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201
(egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> tel = { "jack" : 4098, "sape" : 4139 }
>>> k = tel.keys()
>>> k.sort()
>>> for key in k:
...     print key, tel[key]
... 
jack 4098
sape 4139

there are probably other ways to solve this problem. this works
for me. what did you come up with?

regards,
J
-- 
|| visit gfd <http://quark.newimage.com/> 
|| psa member #293 <http://www.python.org/> 
|| New Image Systems & Services, Inc. <http://www.newimage.com/>




More information about the Python-list mailing list