frnhr
frnhr

Reputation: 12903

Python "map or" on elements in list

What's the most elegant way of doing something like this:

>>> tests = [false, false, false]
>>> map_or(test)
false

>>> tests = [true, false, false]
>>> map_or(test)
true

The map_or function should return true if one or more of list elements are true.

Upvotes: 2

Views: 701

Answers (3)

Sven Marnach
Sven Marnach

Reputation: 602035

Use any(). It is a built-in function that just does what you want.

Upvotes: 9

Tony Veijalainen
Tony Veijalainen

Reputation: 5555

any(tests)

Built in function :)

Upvotes: 5

Glenn Maynard
Glenn Maynard

Reputation: 57514

any(tests)

(and the rest of this is padding because yet again StackOverflow treats users like idiots and sets minimum answer lengths)

Upvotes: 4

Related Questions