Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active January 27, 2025 10:52
Show Gist options
  • Save walkermatt/ce202a67ee4a01c3d885b652063185b6 to your computer and use it in GitHub Desktop.
Save walkermatt/ce202a67ee4a01c3d885b652063185b6 to your computer and use it in GitHub Desktop.
Naïve Quicksort implementation in Python
def qs(l):
if len(l) == 0:
return l
n = l.pop(0)
# print(f'n: {n}')
smaller = [x for x in l if x <= n]
larger = [x for x in l if x > n]
# print(f'smaller: {smaller}')
# print(f'larger: {larger}')
return qs(smaller) + [n] + qs(larger)
if __name__ == '__main__':
print(qs([7,4,5,9,3,2,1,6,8,0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment