Sorting dict keys
nospam.themindstorm at gmail.com
Sat Jul 21 00:50:36 CEST 2007
montyphyton at gmail.com wrote in news:1184970471.146819.86280
I am not sure about your scenario, but as you discovered the sort() method
is modifying the in place list (and doesn't return a new one).
If you just want to iterate over your dict in an ordered manner than all
you have to do is:
for k in my_dict.keys().sort():
# rest of the code
If you just want to keep a list of ordered keys you can probably do
key_list = list(my_dict.keys())
.w( the_mindstorm )p.
More information about the Python-list