python———sort、sorted使用(对dict排序)
一、L.sort(cmp=None,key=None,reverse=False)对L原地排序不会返回新的L
sort使用:
1、key参数定义L=[{2:8,3:5},{1:8,2:5,3:6,4:7},{1:5,2:9,3:6}]
def f(x):
return len(L)
L.sort(key=f)
print(L)结果:
[{2: 8, 3: 5}, {1: 5, 2: 9
原创
2017-03-15 12:04:21 ·
13119 阅读 ·
0 评论