List comprehension vs generator expression’s weird timeit results?
Expanding on Paulo’s answer, generator expressions are often slower than list comprehensions because of the overhead of function calls. In this case, the short-circuiting behavior of in offsets that slowness if the item is found fairly early, but otherwise, the pattern holds. I ran a simple script through the profiler for a more detailed analysis. … Read more