Skip to content

Instantly share code, notes, and snippets.

@wiseaidev
Last active June 1, 2022 18:38
Show Gist options
  • Save wiseaidev/41b264cf1a20b77277a85be25de6d07b to your computer and use it in GitHub Desktop.
Save wiseaidev/41b264cf1a20b77277a85be25de6d07b to your computer and use it in GitHub Desktop.
A pythonic implementation of the sleep sort algorithm.
from concurrent.futures import ThreadPoolExecutor
from time import sleep
from typing import List, Union
def sleep_sort(input_list: List[Union[int, float]]) -> List[Union[int, float]]:
sorted_list: List[Union[int, float]] = []
def inner(item: Union[int, float], sorted_list: List[Union[int, float]]) -> None:
sleep(item)
sorted_list.append(item)
with ThreadPoolExecutor() as executor:
for item in iter(input_list):
_ = executor.submit(inner, item, sorted_list)
return sorted_list
print(sleep_sort([3, 1, 9, 5, 2.5, 7.5, 3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment