all_isinstance

iteration_utilities.all_isinstance(iterable, types)

Like isinstance() but for iterables.

Checks if all items in iterable are instances 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
allbool

True if all elements in iterable are instances of types, False if not.

Examples

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

>>> from iteration_utilities import all_isinstance
>>> all_isinstance(range(100), int)
True

>>> all_isinstance([1, 2, 3.2], (int, float))
True

Warning

This function returns True if the iterable is empty.