Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

python

hoart_sort() takes 1 positional argument but 5 were given

 

from random import choice
def hoar_sort(A):
 from random import choice
def hoar_sort(A):
if len(A)<=1:
return A
barier=random.choice(A)
left=[x for x in A if x<barier]
middle=[x for x in A if x==barier]
rigt=[x for x in A if x>barier]
left=hoar_sort(left)
right=hoar_sort(right)
return left+middle+right

there is a problem?

1 Reply
Highlighted
Commander Lvl 2
Message 2 of 2

Re: python

You need to show us your initial invocation of hoar_sort.

 

You might also try changing:

left=hoar_sort(left)
right=hoar_sort(right)
return left+middle+right

to this:

left2=hoar_sort(left)
right2=hoar_sort(right)
return left2+middle+right2

By using the same name for your input and output you might be confusing the list instances.

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!