Access dictionary in order?
Wolfgang Grafen
wolfgang.grafen at de.bosch.com
Tue Jul 27 08:48:15 EDT 1999
Roy Smith wrote:
>
> 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?
Look here:
Probably seqdict is best for you. Look at
http://www.germany.net/teilnehmer/100,366919/Python/Modules/Modules.html
from seqdict import seqdict
dict = seqdict()
.
.
.
for key,value in dict.items():
do_stuff(key,value)
I think this works for you. But seqdict and mseqdict brings much, much
more
new operations on sequential dictionaries. Tell me what your think.
Wolfgang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wolfgang.grafen.vcf
Type: text/x-vcard
Size: 329 bytes
Desc: Card for Wolfgang Grafen
URL: <http://mail.python.org/pipermail/python-list/attachments/19990727/62e7d6f9/attachment.vcf>
More information about the Python-list
mailing list