append to the end of a dictionary

Sion Arrowsmith siona at
Wed Jan 25 08:53:40 EST 2006

Magnus Lycka  <lycka at> wrote:
>orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())]


orderedListOfTuples = [(k,v) for k,v in sorted(mydict.items())]

(k, mydict[k]) sets off warning bells for me that mydict.items()
should be in use, which are nearly as loud as the ones that
range(len(mylist)) triggers.

\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