I need to check if any of my variables are larger than a threshold.
Currently I'm doing
if b > a or c > a or d > a
... etc
Is there a faster way to write this (similar to if a in {b, c, d}
:?)
I need to check if any of my variables are larger than a threshold.
Currently I'm doing
if b > a or c > a or d > a
... etc
Is there a faster way to write this (similar to if a in {b, c, d}
:?)
I'm not sure of the best approach, but I know the any
built-in function can help with this:
numbers = [8, 9, 4]
threshold = 3
if any(n > threshold for n in numbers):
print("At least one is above the threshold")
else:
print("None are above the threshold")