Skip to content
Incomplete sheet

This sheet is incomplete and could use some attention. Please submit code snippet suggestions as an issue or PR here.

Collections

For an overview of the abstract classes provided by the collections module, see here.

Code

import collections

Test

Action Code Details
Is collection
isinstance(x, collections.abc.Collection)
e.g., str, tuple, list, set, dict
Is sequence (defined ordering of elements)
isinstance(x, collections.abc.Sequence)
e.g., str, tuple, list
Is mapping
isinstance(x, collections.abc.Mapping)
e.g., dict
Is set
isinstance(x, collections.abc.Set)
e.g., set