Python: any() unexpected performance
问题 I am comparing the performance of the any() built-in function with the actual implementation the docs suggest: I am looking for an element greater than 0 in the following list: lst = [0 for _ in range(1000000)] + [1] This is the supposedly equivalent function: def gt_0(lst): for elm in lst: if elm > 0: return True return False And these are the results of the performance tests: >> %timeit any(elm > 0 for elm in lst) >> 10 loops, best of 3: 35.9 ms per loop >> %timeit gt_0(lst) >> 100 loops,