Sort the values of a dict
Rory Campbell-Lange
rory at campbell-lange.net
Sat Dec 19 17:43:31 EST 2009
> >>>>mylist = [z for z in zip(list(d), list(d.values()))]
> The Pythonic way for the above line is:
> >>> mylist = list(d.items())
Quite right. Thanks for pointing that out.
I liked Chris Kaynor's solution:
s = sorted(d.items(), key=lambda i: i[1][2])
I'm a bit rusty, and have just picked up the new "Learning Python" book
but I'm finding that it isn't providing a useful refresher to the
language or a particularly good introduction to version 3. Have you any
suggestions.
Regards
Rory
--
Rory Campbell-Lange
rory at campbell-lange.net
Campbell-Lange Workshop
www.campbell-lange.net
0207 6311 555
3 Tottenham Street London W1T 2AF
Registered in England No. 04551928
More information about the Python-list
mailing list