Skip to content

Instantly share code, notes, and snippets.

@wolph
Created May 30, 2016 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolph/c9ce622fa4752781ff91a7579bc7c9ca to your computer and use it in GitHub Desktop.
Save wolph/c9ce622fa4752781ff91a7579bc7c9ca to your computer and use it in GitHub Desktop.
Implementing the Quick sort algorithm using the Y Combinator
Y = lambda f: lambda *args: f(Y(f))(*args)
quicksort = Y(lambda f:
lambda x: (
f([item for item in x if item < x[0]])
+ [y for y in x if x[0] == y]
+ f([item for item in x if item > x[0]])
) if x else [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment