any()
Introduction
The function any() returns True if at least one object
inside the iterable object is True.
Otherwise it returns False
If the iterable object is empty, then any() will return False
The parameter of the function can be an iterable object
(
a list
,
a tuple,
a dictionary
)
Syntax
any(iterable)
Example
How any() works
# any() print(any([False, False, False])) # -> False print(any([False, False, True])) # -> True
Let's apply these functions to generators.
print(any(is_prime(x) for x in range(1328, 1361))) print(any(is_prime(x) for x in range(99, 102))) print(all(is_prime(x) for x in range(99, 102))) print(all(name == name.title() for name in ['Benalmadena', 'Cordoba', 'Fuengirola', 'Malaga']))
False True False True
Article author: Andrei Olegovich