exDotaPro

sort_numbers

Jan 27th, 2021
766
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import time
  3.  
  4. start_time = time.time()
  5.  
  6. numbers_count = 1000000
  7. my_range = 5000000
  8. random_list = random.sample(range(-my_range, my_range), numbers_count)
  9. positives = [0] * my_range
  10. negatives = [0] * my_range
  11.  
  12. for num in random_list:
  13.     if num > 0:
  14.         positives[num] = num
  15.     else:
  16.         negatives[num] = num
  17.  
  18. sorted_list = list(filter(lambda x: x != 0, negatives)) + list(filter(lambda x: x != 0, positives))
  19. print(sorted_list)
  20. print("--- %s seconds ---" % (time.time() - start_time))
  21.  
RAW Paste Data