In a tutorial, I see a piece of code that I verified works: https://wiki.python.org/moin/HowTo/Sorting
>>> student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
Why is the student[2] known by python to refer to the third element of each tuple? Why didn't it try to sort by the third tuple, instead of the third item of each tuple?
operator.itemgetter(2)would be more efficeint