append to the end of a dictionary
lycka at carmen.se
Wed Jan 25 07:28:30 EST 2006
Tim Chase wrote:
> orderedDict = [(k,mydict[k]) for k in mydict.keys().sorted()]
Wrong. As you stated, sorted() is a function, not a method.
orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())]
It's great that many people try to help out on comp.lang.python,
the community won't survive otherwise, but I think it's important
to test answers before posting them, unless you're sure about your
answer. A wrong answer might actually be worse than no answer at
all. I fear that newbies will just get scared off if they get bunch
a of replies to their questions, and most are wrong.
More information about the Python-list