Why is any(True for ... if cond) much faster than any(cond for ...)?
Two similar ways to check whether a list contains an odd number: any(x % 2 for x in a) any(True for x in a if x % 2) Timing results with a = [0] * 10000000 (five attempts each, times in seconds): 0.60 0.60 0.60 0.61 0.63 any(x % 2 for x in a) 0.36 0.36 0.36 0.37 0.37 any(True for x in a if x % 2) Why is the second way almost twice as fast? My testing code: f