Skip to content

Instantly share code, notes, and snippets.

@ohe
Created September 20, 2016 14:43
Show Gist options
  • Save ohe/70bb02c96e512a109c2ced7599201e4d to your computer and use it in GitHub Desktop.
Save ohe/70bb02c96e512a109c2ced7599201e4d to your computer and use it in GitHub Desktop.
The only sort algorithm you need
from threading import Thread
import time
a = [3, 1, 4]
def sleepsort(array):
results = []
threads = []
def runner(x):
time.sleep(x)
results.append(x)
for x in array:
t = Thread(target=runner, args=(x,))
t.start()
threads.append(t)
for t in threads:
t.join()
return results
print sleepsort(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment