Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created July 6, 2023 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengruppetta/d37082c32806629ae763b03592cd9006 to your computer and use it in GitHub Desktop.
Save stephengruppetta/d37082c32806629ae763b03592cd9006 to your computer and use it in GitHub Desktop.
import collections
team_members = ["Jim", "Chris", "Jess", "Zahra"]
# A list is a sequence
print(isinstance(team_members, collections.abc.Sequence))
# True
# It's not a mapping
print(isinstance(team_members, collections.abc.Mapping))
# False
# And it's not a set, either
print(isinstance(team_members, collections.abc.Set))
# False
# All sequences are collections…
print(isinstance(team_members, collections.abc.Collection))
# True
# …and all collections are sized, iterable containers
print(isinstance(team_members, collections.abc.Sized))
# True
print(isinstance(team_members, collections.abc.Iterable))
# True
print(isinstance(team_members, collections.abc.Container))
# True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment