algorithm - Quick Sort using Python -


i wondering if can me fix error code quick sort has: not compile , highlights last line of code in red. can not figure out wrong. sort defined function why highlighted red?

def sort(*myarray):     less = []     equal = []     greater = []      if len(myarray) > 1:         pivot = myarray[0]         x in myarray:             if x < pivot:                 less.append(x)             if x == pivot:                 equal.append(x)             if x > pivot:                 greater.append(x)         return sort(less)+sort(equal)+sort(greater)     else:         return myarray print sort([12,4,5,6,7,3,1,15]) 

you're defining function taking variable number of arguments (the *myarray bit), using myarray inside single argument (the list sort), when list containing list sort.

you should remove * function parameter. this questions esplains quite thoroughly.

you keep *, have play bit tuple unpacking same result.

edit

although above true, might not issue you're encountering.

idle give invalid syntax error on ast line, because in interactive mode - lines starting >>>, accepts 1 statement @ time. in case statement sort() definition.

try hitting enter 2 times after function definition, should repl, can introduce statement (print sort([12,4,5,6,7,3,1,15]))


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -