Advanced sorting: sorting by key
Monday, April 14th, 2008The sort() method of list objects in Python is quite flexible. By default, it sorts on the first thing in each item of the list, which is exactly what you would expect. For example, a list of strings is sorted by the first letter of each string. What if you wanted to sort by the second letter of each string? Or sort a list of people’s names by last name? (more…)