Walk through dictionary keys?
Emile van Sebille
emile at fenx.com
Tue Dec 19 11:34:44 EST 2000
I'm not sure when or how long this has been in, but the cvs version of
dict's has a popitem method that looks like it does what you want.
d = {1:11,2:22,3:33,4:44}
for i in xrange(len(d)):
print d.popitem()
HTH,
Emile van Sebille
emile at fenx.com
Carsten Gaebler wrote:
> Hi!
>
> Is there a way of 'walking' through the keys of a dictionary? If I have
> a large dictionary I'd like to prevent
>
> for key in d.keys():
> do_something
>
> because this makes a copy of all the keys. I'm looking for something
> like Perl's "each".
>
> Regards
> Carsten.
More information about the Python-list
mailing list