append to the end of a dictionary

Sion Arrowsmith siona at
Tue Jan 24 17:04:46 CET 2006

Tim Chase  <python.list at> wrote:
>unless you have a way of doing an in-line sort, in which you 
>would be able to do something like
>   orderedDict = [(k,mydict[k]) for k in mydict.keys().sort()]
>Unfortunately, the version I've got here doesn't seem to support 
>a sort() method for the list returned by keys(). :(

I bet it does, but it doesn't do what you think it does. See , in particular
note 7.

What you want is the sorted() function (introduced in 2.4 IIRC).

\S -- siona at --
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list