Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python "map or" on elements in list

Tags:

python

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.

like image 996
frnhr Avatar asked Dec 30 '25 08:12

frnhr


2 Answers

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

like image 176
Sven Marnach Avatar answered Jan 02 '26 01:01

Sven Marnach


any(tests)

Built in function :)

like image 35
Tony Veijalainen Avatar answered Jan 02 '26 00:01

Tony Veijalainen