Dictionary sorting

insomnia at gmail.com insomnia at gmail.com
Thu Nov 3 16:01:36 EDT 2011


Moreover, for on-the-fly ordering you can consider to use sorted() on yourdict.keys(), like:

for k in sorted(yourdict.keys()):
    print k, yourdict[k]

I think it has no side effects, except that the orderering can be slow on huge data sets, and that you need to call it every time after updating the dict keys.

Regards,
insomniac



More information about the Python-list mailing list