I am done with my sleepsort code, it should give every number in the list the time it has to sleep and the first to wake up should be moved in the list. but is there a way to make my code look simpler:
import threading
import time
unsortet_array = [5, 1, 7, 3, 10]
sortet_array = []
print('Here is the unsorted array:', unsortet_array)
def first_element():
time.sleep(unsortet_array[0])
sortet_array.append(unsortet_array[0])
def second_element():
time.sleep(unsortet_array[1])
sortet_array.append(unsortet_array[1])
def third_element():
time.sleep(unsortet_array[2])
sortet_array.append(unsortet_array[2])
def fourth_element():
time.sleep(unsortet_array[3])
sortet_array.append(unsortet_array[3])
def fifth_element():
time.sleep(unsortet_array[4])
sortet_array.append(unsortet_array[4])
first = threading.Thread(target=first_element)
first.start()
second = threading.Thread(target=second_element)
second.start()
third = threading.Thread(target=third_element)
third.start()
fourth = threading.Thread(target=fourth_element)
fourth.start()
fifth = threading.Thread(target=fifth_element)
fifth.start()
first.join()
second.join()
third.join()
fourth.join()
fifth.join()
print("Here is the sortet array:", sortet_array)