Python 字典 列表 复杂数据结构 排序

x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}

sorted = sorted(x.iteritems(), key=lambda x: x[1], reverse=True)

import operator;sorted = sorted(x.iteritems(), key=operator.itemgetter(1), reverse=True)

x = [(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]

sorted = sorted(x.iteritems(), key=lambda x: x[1], reverse=True)

import operator;sorted = sorted(x.iteritems(), key=operator.itemgetter(1), reverse=True)

x = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]

sorted = sorted(x, key=operator.itemgetter('name'))

参考文献:

https://blog.csdn.net/xiaoQL520/article/details/78134260

你可能感兴趣的:(数据结构,列表,redis,python,docker)