We are misusing the all() and any() Python's built-in functions. Wrapping the iterable in [] converts it into a list before the function is called, which unnecessarily increases the runtime to the worst-case which is O(n) in every case.
What we are currently doing:
>>> import timeit
>>> timeit.timeit('any([n > 0 for n in range(10000)])', number=10000)
4.729606243010494
How it should be:
>>> import timeit
>>> timeit.timeit('any(n > 0 for n in range(10000))', number=10000)
0.019788431003689766
We are misusing the
all()
andany()
Python's built-in functions. Wrapping the iterable in [] converts it into a list before the function is called, which unnecessarily increases the runtime to the worst-case which is O(n) in every case.What we are currently doing:
How it should be: