EdisonChendi
12/11/2016 - 2:23 PM

sort_sorted.py

# coding=UTF-8

import operator
engineers = [{"name": "John", "age": 28}, {"name": "Peter", "age": 20}, {"name": "Paul", "age": 33}]
engineers_sorted_by_age = sorted(engineers, key=operator.itemgetter("age"))
print(engineers_sorted_by_age)
print(engineers)
engineers.sort(key=operator.itemgetter("age"), reverse=True)
print(engineers)