def sortby(somelist, n):
    """
    Suppose, for example, you have a list of tuples that you want to sort by the n-th field of each tuple.
    """
    nlist = [(x[n], x) for x in somelist]
    nlist.sort()
    return [val for (key, val) in nlist]