How do you apply ‘or’ to all values of a list in Python? I’m thinking something like:
or([True, True, False])
or if it was possible:
reduce(or, [True, True, False])
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The built-in function
anydoes what you want:anyhas the advantage overreduceof shortcutting the test for later items in the sequence once it finds a true value. This can be very handy if the sequence is a generator with an expensive operation behind it. For example:If your Python’s version doesn’t have
any(),all()builtins then they are easily implemented as Guido van Rossum suggested: