In this code, why is the second output faster than the first!?
Both do almost the same thing and have the same result.
from timeit import timeit
lst = [0] * 10000000
txt1 = "any(i % 2 for i in lst)"
txt2 = "any(True for i in lst if i % 2)"
print(timeit(txt1, globals=globals(), number=2))
print(timeit(txt2, globals=globals(), number=2))
result:
Time : 2.112963530991692
Time : 0.9412867689970881