Python — Why Python list are slower when sorted
In the following code, I create two lists with the same values: one list unsorted (s_not), the other sorted (s_yes). The values are created by randint(). I run some loop for each list and time it.
import random
import timefor x in range(1,9): r = 10**x # do different val for the bound in randint()
m = int(r/2) print("For rand", r) # s_not is non sorted list
s_not = [random.randint(1,r) for i in range(10**7)]