def sort_by_index(a, idx, reverse=False):
    """
    Sort an array of array by index

    Input:
        a: a 2D array, e.g., [[1, "a"], [2, "b"]]
        idx: the index to sort the arrays inside the array, e.g., 0
    """
    return sorted(a, key=lambda t: t[idx], reverse=reverse)