How to sort using hash's key?

Steven Bethard steven.bethard at gmail.com
Wed Jan 31 19:08:54 EST 2007


JoJo wrote:
> I want to sort a dict via its key,but I have no idea on how to do it.

>>> d = dict(a=2, b=1)
>>> for key in sorted(d):
...     print key, d[key]
...
a 2
b 1

STeVe



More information about the Python-list mailing list