# quick sort

def quick_sort(L):
    ''' (list) -> list

    Return a new list with the same elements as L in
    ascending order.

    >>> L = []
    >>> quick_sort(L)
    []
    >>> L = [17]
    >>> quick_sort(L)
    [17]
    >>> L = [3, 1, 2]
    >>> quick_sort(L)
    [1, 2, 3]
    '''
    if L == []:
        # copy of L
        return []
    else:
        return (quick_sort([i for i in L if i < L[0]]) +
                [L[0]] +
                quick_sort([i for i in L[1:] if i >= L[0]]))


if __name__ == '__main__':
    import doctest
    doctest.testmod()
    L = list(range(100000))
    import random
    random.shuffle(L)
    import time
    start = time.time()
    quick_sort(L)
    print('sorting took {} seconds.'.format(time.time() - start))
