Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 559 Bytes

19.md

File metadata and controls

25 lines (19 loc) · 559 Bytes
@author jackzhenguo
@desc 
@date 2019/2/20

19 拿来就用的排序函数

排序:

In [1]: a = [1,4,2,3,1]

In [2]: sorted(a,reverse=True)
Out[2]: [4, 3, 2, 1, 1]

In [3]: a = [{'name':'xiaoming','age':18,'gender':'male'},{'name':'
     ...: xiaohong','age':20,'gender':'female'}]
In [4]: sorted(a,key=lambda x: x['age'],reverse=False)
Out[4]:
[{'name': 'xiaoming', 'age': 18, 'gender': 'male'},
 {'name': 'xiaohong', 'age': 20, 'gender': 'female'}]
[上一个例子](18.md) [下一个例子](20.md)