Tag Archive for 'sort'

Advanced sorting: sorting by key

The 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? Continue reading ‘Advanced sorting: sorting by key’

Sort one list by another list

Here are a couple of ways of sorting one list by another list in Python. The first uses plain ol’ Python, and the others use NumPy.

In each case imagine we want to sort a list of peoples names by their ages. Continue reading ‘Sort one list by another list’