Of the following list based on age sort
items = [{ 'age': 28, 'name': 'Tom'}, { 'age': 25, 'name': 'Jack'}, { 'age': 18, ' name ':' Alex '}]
Method a:
the sorted (items, the lambda = Key Item: Item [ 'Age'])
方法二:
from operator import itemgetter
sorted(items,key=itemgetter('age'))
Note: The above two methods are equally applicable to the max (), min () function