Skip to content

Instantly share code, notes, and snippets.

View apallin's full-sized avatar

Adam Pallin apallin

  • Offsyte
  • Nashville
View GitHub Profile
@apallin
apallin / gen_substrings.py
Last active January 12, 2022 22:43
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