Access dictionary in order?
Roy Smith
roy at popmail.med.nyu.edu
Sun Jul 25 13:00:36 EDT 1999
I've got a dictionary of items which I will sometimes want random access
to, but sometimes I'll want to be able to step through the items in a
fixed order as well. Any good way to do that?
The best I've come up with so far is to keep a parallel list of the
dictionary keys in sorted order and use that to step through when I need
to:
for key in keylist:
do_stuff (dict[key])
which will work, but seems kind of clumsy. Anything smoother I can do?
More information about the Python-list
mailing list