any_isinstance

iteration_utilities.any_isinstance(iterable, types)

Like isinstance() but for iterables.

Checks if any item in iterable is an instance of types.

Parameters:
iterableiterable

Each item of the iterable is tested with isinstance(item, types).

typestype or tuple of types

Test for this type if it’s a single class or test if the item is of any of the types (if types is a tuple).

Returns:
anybool

True if any elements in iterable is an instance of types, False if not.

Examples

This function is equivalent (but faster) than any(isinstance(item, types) for item in iterable)

>>> from iteration_utilities import any_isinstance
>>> all_isinstance(range(100), int)
True
>>> any_isinstance([1, 2, 3.2], float)
True