Skip to content

Instantly share code, notes, and snippets.

@juanarrivillaga
Last active May 20, 2017 23:45
Show Gist options
  • Save juanarrivillaga/6ef6deef3d2ab627eb882c9460de80b2 to your computer and use it in GitHub Desktop.
Save juanarrivillaga/6ef6deef3d2ab627eb882c9460de80b2 to your computer and use it in GitHub Desktop.
"""
An exampe quicksort implementation, demonstrating pythonic style
(albeit using inefficient `+` to concatenate lists...)
"""
def quicksort(seq):
if len(seq) <= 1:
return seq
pivot, *rest = seq
smaller = quicksort([x for x in rest if x <= pivot])
larger = quicksort([x for x in rest if x > pivot])
return smaller + [pivot] + larger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment