+1 vote

I am a beginner in Python and i want to implement quicksort in my code. I need help in concatenating the three arrays and print them. how do i do it in the following code :

```def sort(array=[18,4,5,9,7,1,3,12):
less = []
equal = []
greater = []

if len(array) > 1:
pivot = array[0]
for x in array:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
sort(less)
sort(pivot)
sort(greater)```
Sep 20, 2018 in Python 502 views

`The following code may solve your problem:`

```def sort(array=[18,4,5,9,7,1,3,12]):
less = []
equal = []
greater = []

if len(array) > 1:
pivot = array[0]
for x in array:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
# Don't forget to return value!
return sort(less)+equal+sort(greater)  # use the + operator to join lists
# Note that you want equal ^^^^^ not pivot
else:  # You need to handle the part at the end of the recursion - when you only have one element in your array, just return the array.
return array```
• 13,300 points

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

How can I create a new file in Python?

You can try the below code which ...READ MORE

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

Error while printing hello world in python.

You must be trying this command in ...READ MORE

+1 vote

how do i change string to a list?

suppose you have a string with a ...READ MORE

how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE