<jupyter_start><jupyter_text>Quick Sort© 2021, <NAME><jupyter_code>import random

def quick_sort(A):
    quick(A, 0, len(A)-1)

def quick(A, low, hi):
    if low < hi:
        p = partition(A, low, hi)
        quick(A, low, p-1)
        quick(A, p+1, hi)

def get_pivot(A, low, hi):
    return random.randrange(low, hi+1)
    
def partition(A, low, hi):
    pivotIndex = get_pivot(A, low, hi)
    pivotValue = A[pivotIndex]
    A[pivotIndex], A[low] = A[low], A[pivotIndex]
    border = low

    for i in range(low, hi+1):
        if A[i] < pivotValue:
            border += 1
            A[i], A[border] = A[border], A[i]
    A[low], A[border] = A[border], A[low]

    return (border)<jupyter_output><empty_output><jupyter_text>Test FunctionSet a result flag. The j loop is used to perform 1000 test iterations. The next two lines create and shuffle list A of 100 integers. Then A is passed to our sorting function. The sorted result is compared to a sort using Python's sorted function. After 1000 iterations of the test, the result is printed.<jupyter_code>def test(func):
    result = 'Success'
    for j in range(1000):
        A = [k for k in range(100)]
        random.shuffle(A)
        func(A)
        if A != sorted(A):
            result += 'Failed' + str(j)
    print(result)
test(quick_sort)<jupyter_output>Success
{'fraction_non_alphanumeric': 0.12434061793519216, 'fraction_numerical': 0.02185380557648832, 'mean_word_length': 2.9523809523809526, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '425240', 'license': 'MIT', 'n_tokens_mistral': 495, 'n_tokens_neox': 461, 'n_words': 149, 'path': 'Sorting Algorithms/Quick Sort.ipynb', 'repo_name': 'joeyajames/udemy_algorithms', 'size': '1330'}