demo_ref_list_sort5.py:
def myFunc(e): return e['year'] cars = [ {'car': 'Ford', 'year': 2005}, {'car': 'Mitsubishi', 'year': 2000}, {'car': 'BMW', 'year': 2019}, {'car': 'VW', 'year': 2011} ] cars.sort(key=myFunc) print(cars)
C:\Users\My Name>python demo_list_sort5.py
[{'car': 'Mitsubishi', 'year': 2000}, {'car': 'Ford', 'year': 2005}, {'car': 'VW', 'year': 2011}, {'car': 'BMW', 'year': 2019}]