-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi,
I think the reason you give in https://github.com/switowski/writing-faster-python3/blob/main/any.py is not correct, it
is not because of list construction overhead, but because the 'or' function stops when something is True.
Speed is the same if all variables are '0' :
a,b,c,d,e,f = 0,0,0,0,0,0
or
a,b,c,d,e,f = 0,0,0,0,0,1
--
However, there is another interesting situation: defining the list outside the function does seem to be faster (in some situations):
x = [a, b, c, d, f]
def test_any():
return 1 if any(x) else 0
Metadata
Metadata
Assignees
Labels
No labels