Sorting becomes more useful when the original items are not already arranged by the value you need. Pass a callable to sorted’s key parameter; Python calls it once per element and orders items by the returned keys. section 3.26
Sort names by last name, then first name
Use a function that extracts a comparison key from each dictionary. A tuple key expresses the two-level ordering directly; a lambda can provide the same behavior inline, while operator.itemgetter offers another valid approach. section 3.11 section 3.15
PEOPLE = [{'first':'Reuven', 'last':'Lerner',
'email':'reuven@lerner.co.il'},
{'first':'Donald', 'last':'Trump',
'email':'president@whitehouse.gov'},
{'first':'Vladimir', 'last':'Putin',
'email':'president@kremvax.ru'}
]
Try the sorting exercise with this PEOPLE sequence, returning dictionaries ordered by last name and then first name. section 3.11
Practice by changing the extracted key:
- Sort positive and negative numbers by absolute value. section 3.15
- Sort strings by their number of vowels or lists by the sum of their numbers. section 3.15

