Sort dictionary

Markus Franz mail at markus-franz.de
Mon Jan 2 10:43:45 EST 2006


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



More information about the Python-list mailing list