I have list:
[
{'name': 'peter', 'age': 41, 'value': 1},
{'name': 'jon', 'age': 31, 'value': 5},
{'name': 'alan', 'age': 23, 'value': 3}
]
How to sort this list by 'age'?
You can use a lambda function and one of the following functions to sort:
If you want to sort in-place (modify the list):
L.sort(key = lambda d:d['age'])
If you want to create a new sorted list:
print sorted(L, key = lambda d:d['age'])