Skip to content

any.py #1

@Alex-CodeLab

Description

@Alex-CodeLab

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions