On Wed, 7 Jul 2010 12:38:55 am Ken G. wrote:
> Is there a way to sort a dictionary?
Not directly, dictionaries are unsorted and unsortable. They print in an
arbitrary order.
If you need to operate on dictionaries in a specific, non-arbitrary
order, you need to extract the keys, sort them, and then work from
them. Example:
keys = mydict.keys()
keys.sort()
for key in keys:
value = mydict[key]
print "the value of key %s is %s" (key, value)
I'm sure you can adapt that example to what you're trying to do :)
--
Steven D'Aprano
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor