An ordered dictionary for the Python library?

Jürgen Urner jUrner at arcor.de
Thu Sep 13 21:35:08 EDT 2007


Puh, what a discussion... most common use case I can think of is

>> d = {'a': 1, 'b': 2, 'c': 3}
>> for key in d:
>>     # do something that relies on order of keys as specified in the constructor


It's a bit tireing having to type

>> for key in sorted(d.keys()):
>>     do_somethig_with(d[key])

instead of a trustfully

>> for value in d.values():
>>     do_somethig_with(value)

As far as I can see much cleaner. No black magic needed ++ sort the
dict
to another order and rely on the sort order being stable would be a
really
a nice thing to have.


My 2 cents,  Jürgen




More information about the Python-list mailing list