Skip to content

Instantly share code, notes, and snippets.

@bashkirtsevich
Created November 5, 2019 16:29
Show Gist options
  • Save bashkirtsevich/da4440ed2ca5610d021fa54aaa9fa386 to your computer and use it in GitHub Desktop.
Save bashkirtsevich/da4440ed2ca5610d021fa54aaa9fa386 to your computer and use it in GitHub Desktop.
Quicksort
from itertools import tee, chain
def sort_c(it):
xs = iter(it)
x = next(xs)
xs1, xs2 = tee(xs)
yield from chain(
sort_c(filter(lambda i: i < x, xs1)),
[x],
sort_c(filter(lambda i: i >= x, xs2))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment