def quick_sort(m):
    """Select a random number (pivot), then divide the array into 3
    arrays of [smaller than pivot], [equal to pivot], and [larger than pivot],
    and merge them again in quick_sort([small])-[equal]-quick_sort([large])
    order"""
    if len(m) <= 1:
        return m
    pivot = m[0]  # random pivot
    less, equal, more = [], [], []
    for x in m:
        if x < pivot:
            less.append(x)
        elif x > pivot:
            more.append(x)
        else:
            equal.append(x)
    return quick_sort(less) + equal + quick_sort(more)