Skip to content

Instantly share code, notes, and snippets.

@nenetto
Created September 26, 2023 10:38
Show Gist options
  • Save nenetto/e6f1c47e729fb1819307254fa7881c92 to your computer and use it in GitHub Desktop.
Save nenetto/e6f1c47e729fb1819307254fa7881c92 to your computer and use it in GitHub Desktop.
Itertools
import itertools
# Linking iterators together
# chain: Combines multiple iterators into a single sequential iterator.
# cycle: Repeats an iterator’s items forever.
# tee: Splits a single iterator into multiple parallel iterators.
# zip_longest: A variant of the zip built-in function that works well with iterators of different lengths.
# Filtering items from an iterator
# islice: Slices an iterator by numerical indexes without copying
# takewhile: Returns items from an iterator while a predicate function returns True.
# dropwhile: Returns items from an iterator once the predicate function returns False for the first time.
# filterfalse: Returns all items from an iterator where a predicate function returns False. The opposite of the filter built-in function.
# Combinations of items from iterators
# product: cartesian products of two iterators
# permutations
# combination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment