append to the end of a dictionary

Sion Arrowsmith siona at chiark.greenend.org.uk
Tue Jan 24 11:04:46 EST 2006


Tim Chase  <python.list at tim.thechases.com> 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
http://docs.python.org/lib/typesseq-mutable.html , in particular
note 7.

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

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "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