python---算法之睡眠排序

   通過睡眠來排序:

from threading import Thread
import time


list_x = [1, 0.2, 0.5, 2, 0.9, 0.95]

list_y = []
def action(time_value):
         time.sleep(time_value)
         list_y.append(time_value)

thread_pool = []

for i in list_x:
         t = Thread(target=action, args=(i,))
         thread_pool.append(t)

for t in thread_pool:
         t.start()
for t in thread_pool:
         t.join()

print(list_y)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章