Sorting algorithms/Quicksort: Difference between revisions

m
If you tried to run the offending code, you will get "TypeError: object of type 'filter' has no len()". So this means you either change the type to list or tuple.
m (If you tried to run the offending code, you will get "TypeError: object of type 'filter' has no len()". So this means you either change the type to list or tuple.)
Line 8,649:
def quicksort(unsorted_list):
if len(unsorted_list) == 0:
return ()[]
pivot = unsorted_list[0]
less = list(filter(lambda x: x < pivot, unsorted_list))
same = list(filter(lambda x: x == pivot, unsorted_list))
more = list(filter(lambda x: x > pivot, unsorted_list))
 
return quicksort(less) + same + quicksort(more)
1

edit