Last active
June 1, 2022 18:38
-
-
Save wiseaidev/41b264cf1a20b77277a85be25de6d07b to your computer and use it in GitHub Desktop.
A pythonic implementation of the sleep sort algorithm.
This file contains 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
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