def sortArray(data, pos, reverse=False):
    """data is a list of items
    sort by pos in list; reverse if True
    """
    T = []
    for i, M in enumerate(data):
        try:
            T.append((M[pos], i))
        except IndexError:
            return data
    D = dict(zip(T, data))
    T.sort()
    if reverse:
        T.reverse()
    X = []
    for key in T:
        X.append(D[key])
    return X
