Sort dictionary

Claudio Grondi claudio.grondi at freenet.de
Mon Jan 2 10:46:02 EST 2006


Markus Franz wrote:
> Hi!
> 
> I have:
> 
> x = {'a':3, 'b':2, 'c':4}
> 
> How can I sort x by value? (I tried using sorted() with x.items() - but I
> didn't get a dictionary as response.)
> 
> My second question:
> How can I reduce the dictionary to 2 items (so delete everything after the
> first two items)
> 
> Thanks in advance.
> 
> Best regards,
> Markus

See my reply in de.comp.lang.python

Claudio



More information about the Python-list mailing list