python Map 排序

python字典按照value进行排序
例子如下:

>>> d = {'a':1,'b':4,'c':2}
>>> f = zip(d.values(), d.keys() )
>>> f
[(1, 'a'), (2, 'c'), (4, 'b')]
>>> sorted(d.items(), key = lambda x:x[1], reverse = True)
[('b', 4), ('c', 2), ('a', 1)]
>>> import operator
>>> sorted(d.items(), key = operator.itemgetter(1), reverse = True)
[('b', 4), ('c', 2), ('a', 1)]
>>> sorted(d.iteritems(), key = operator.itemgetter(1), reverse = True)
[('b', 4), ('c', 2), ('a', 1)]
>>> sorted(d.iteritems(), key = operator.itemgetter(1), reverse = True)
[('b', 4), ('c', 2), ('a', 1)]
>>>

你可能感兴趣的:(python)