Quicksort in Python

How to print the sorted array?

Here’s the code:
def quicksort(arr):

if len(arr) <= 1:
	return arr

pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)

number_of_elements = int(input())

numbers = []

for i in range(number_of_elements):
i = int(input())
numbers.append(i)

quicksort(numbers)

Hey @developerkushal, you can use for loop as followed to print the array.

for ix in array:
print(ix,end = ’ ')

Hope this cleared your doubt. :blush:

But how do I return the array from the function?

I would strongly recommend you to watch the python basics videos again. Don’t hurry things up, first watch the basics than only you can proceed further. You can’t do this question without understanding lists and its operations.

Hope this cleared your doubt. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.