How to print each recursion of function (quicksort as a example) like this:
[0] 1 [5, 3, 99, 22, 24, 11, 303, 3821]
[3] 5 [99, 22, 24, 11, 303, 3821]
[22, 24, 11] 99 [303, 3821]
[11] 22 [24]
[] 303 [3821]
instead of this:
[0] 1 [5, 3, 99, 22, 24, 11, 303, 3821]
[3] 5 [99, 22, 24, 11, 303, 3821]
[22, 24, 11] 99 [303, 3821]
[11] 22 [24]
[] 303 [3821]
Should it be done with f-strings are maybe in another way?
def quicksort(values):
if len(values) <= 1:
return values
pivot = values[0]
less_than_pivot = []
greater_than_pivot = []
for value in values[1:]:
if value <= pivot:
less_than_pivot.append(value)
else:
greater_than_pivot.append(value)
print(f"{less_than_pivot} {pivot} {greater_than_pivot}")
return quicksort(less_than_pivot) + [pivot] + quicksort(greater_than_pivot)
numbers = [1, 5, 0, 3, 99, 22, 24, 11, 303, 3821]
sorted_numbers = quicksort(numbers)