Created
July 4, 2019 19:24
-
-
Save eivl/f3fcfd553bcd18934bd102b860b866ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| def quick_sort(list_of_numbers): | |
| if len(list_of_numbers) <= 1: | |
| return list_of_numbers | |
| pivot = random.choice(list_of_numbers) | |
| less_then = [n for n in list_of_numbers if n < pivot] | |
| equal = [n for n in list_of_numbers if n == pivot] | |
| greater_then = [n for n in list_of_numbers if n > pivot] | |
| return quick_sort(less_then) + equal + quick_sort(greater_then) | |
| l = [i for i in range(100_000)] | |
| random.shuffle(l) | |
| sorted_l = quick_sort(l) | |
| print(sorted_l[:10]) |
Author
eivl
commented
Nov 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment