[Tutor] help with sorted()
Rick Pasotto
rick at niof.net
Sun Aug 17 17:50:41 CEST 2008
I have a dictionary that looks like: d = {k:[v1,[v2,v3,v4]]}
v1,v2,v3,v4 are integers.
I want to print the dictionary sorted by v1, high to low.
sorted(d,operator.itemgetter(0),reverse=True)
gives me the keys in some order different than if I just looped through
the dictionary and not in key order but also not in any order that I can
see. It really appears random.
sorted(d) does give me a sorted list of keys.
How do I sort on v1? How would I sort on v3?
--
"Many people think that if they were only in some other place, or had
some other job, they would be happy. Well, that is doubtful. So get as
much happiness out of what you are doing as you can and don't put off
being happy until some future date." -- Dale Carnegie
Rick Pasotto rick at niof.net http://www.niof.net
More information about the Tutor
mailing list