Sort dictionary

Markus Franz mail at
Mon Jan 2 16:43:45 CET 2006


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,

More information about the Python-list mailing list