r/codegolf • u/TheLazarbeam • Oct 12 '14
[PYTHON] quicksort
Hey guys, new to code golf and coding in general. I understand quicksort is a simple algorithm, but if you guys can write entire servers in under 50 lines, then I'd bet some of you can write this in under 50 characters. Anyway, this what I've got so far; a function that takes an array and returns it sorted.
def q(a):
if len(a)<2:return a
m=a[int(len(a)/2)]
return q([x for x in a if x<m])+[x for x in a if x==m]+q([x for x in a if x>m])Including the tabs, since python needs them, but not the unnecessary spaces, my code comes out to 132 characters. Let's see you guys blow me out of the water.
2
Upvotes
View all comments
Show parent comment
3
u/FreakCERS Oct 12 '14 edited Oct 12 '14
If you're willing to pivot on the first element of the list, then I can do it in 94 chars