Sorting a dictionary

Jarkko Torppa torppa at polykoira.megabaud.fi
Mon Mar 13 17:56:19 EST 2000


In article <8ajk92$k20$1 at alexander.INS.CWRU.Edu>, rbl at hal.cwru.edu wrote:
>I have thousands of entries in a Python dictionary:
>
>mydict
>
>where the entries are:
>{'word1, word2', integer}
>
>I'd like to sort the dictionary in decreasing order on the
>integer values.
...
>Is there a straightforward and/or accepted way to do this
>from within Python?

Dunno about accepted but I usally write it like this

l=map(lambda x:(x[1][2], x[1][1], x[1][0], x[0]), mydict.items())
l.sort()

-- 
 Jarkko Torppa                torppa at staff.megabaud.fi
  Megabaud Internet-palvelut



More information about the Python-list mailing list