**Code:**

from random import randint

def quicksort(array):

if len(array) < 2:

return array

low, same, high = [], [], []

pivot = array[randint(0, len(array) – 1)] #random `pivot` element

for item in array:

if item < pivot:

low.append(item)

elif item == pivot:

same.append(item)

elif item > pivot:

high.append(item)

print(“low = “, low, “same = “, same, “high = “, high)

return quicksort(low) + same + quicksort(high) #recursive call

oArray = [2, 8, 9, 4, 26, 82, 56, 43]

print(“Original array”, oArray)

nArray = quicksort(oArray)

print(“Sorted array”, nArray)

**Output:**

Original array [2, 8, 9, 4, 26, 82, 56, 43]

low = [2] same = [4] high = [8, 9, 26, 82, 56, 43]

low = [8, 9, 26, 43] same = [56] high = [82]

low = [8, 9] same = [26] high = [43]

low = [8] same = [9] high = []

Sorted array [2, 4, 8, 9, 26, 43, 56, 82]