Skip to content

Instantly share code, notes, and snippets.

@apallin
Last active January 12, 2022 22:43
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 apallin/8d388b4d2873fd0f24d5eb35198380fa to your computer and use it in GitHub Desktop.
Save apallin/8d388b4d2873fd0f24d5eb35198380fa to your computer and use it in GitHub Desktop.
Sliding window iterable for substring generation
from itertools import islice
from itertools import tee
def gen_substrings(iterable, size):
iterables = tee(iter(iterable), size)
window = zip(*(islice(t, n, None) for n, t in enumerate(iterables)))
yield from window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment