Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform logical operations OR on list [multiple elements]?

Is there any way to compare the list elements and return the outcome value ? Below is the python snippet, where it recieves two values and returns the value.

def logical_or_decision(a,b):
    return a or b

value = logical_or_decision(1,0)
print value

I need to make it generic & scalable to more than 2 elements.How can i do it for more than 2 elements ?

like image 803
Jackie Avatar asked Jan 04 '23 21:01

Jackie


1 Answers

There's a built-in function that does this: any.

>>> any([0,0,1,0])
True

>>> any([0,0,0])
False
like image 147
Filip Haglund Avatar answered Jan 13 '23 13:01

Filip Haglund