返回:
– 一个新list对象
sorted对字典dict排序
①按键key排序
from operator import itemgetter
dict = {3: 'B', 1: 'A', 2:...'
[(1, ‘A’), (2, ‘C’), (3, ‘B’)] <class ‘list’
[(3, ‘B’), (2, ‘C’), (1, ‘A’)] <class ‘list’
②按值value...如果是'123'字符串数字可以使用int。...对字典中的多维list进行排序
d2 = {
'Apple': [['44', 88], ['11', 33], ['22', 88]],
'Banana': [['55', 43], ['11...key, value in d2.items():
d2[key] = sorted(value, key=lambda x:(x[1], -int(x[0]))) # 按list第二列升序,相同则按第一列降序