python———sort、sorted使用(對dict排序)

1、L.sort(cmp=None,key=None,reverse=False)對L原地排序不會返回新的L sort使用: 一、key參數定義python 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
相關文章
相關標籤/搜索