import time


def lomuto_partition_scheme(L, draw_data, time_delay, low, high):
    """
    Used as a component in quicksort algorithm.\n
    Prepares partition such that all values up to index i are smaller than
    the pivot and all values from i + 1 are greater than the pivot
    """
    i = low - 1
    pivot = L[high]

    old_highlight_idx = [] ## Display data ##

    for j in range(low, high):
        if L[j] <= pivot:
            i += 1
            L[i], L[j] = L[j], L[i]

    ################ Display data ################
            new_highlight_idx = [i, j]
            draw_data(old_highlight_idx, new_highlight_idx)
            old_highlight_idx = new_highlight_idx
            time.sleep(time_delay)
    draw_data(old_highlight_idx, [])
    ##############################################

    L[i+1], L[high] = L[high], L[i+1]
    return i + 1