Dictionaries
Neil Schemenauer
nas at python.ca
Tue Jul 16 17:31:25 EDT 2002
Marcus Vinicius Laranjeira wrote:
> How can I change the order of the items in a dictionary !?!?!?
Dictionaries are implemented as hash tables. They do not store entries
in sorted order. Maybe you want to use the .sort() method. Eg.
>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> d.keys()
['a', 'c', 'b']
>>> keys = d.keys()
>>> keys.sort()
>>> keys
['a', 'b', 'c']
> Thanks a lot,
No problem.
Neil
More information about the Python-list
mailing list