Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Agree.

The sort of python user who regularly writes stuff like zip(seq, islice(seq, 1, None)))

may enjoy the `itertoolz` library

    https://github.com/pytoolz/toolz
which (among many other handy functions) has a sliding_window function:

    def sliding_window(n, seq):
      """ A sequence of overlapping subsequences
      >>> list(sliding_window(2, [1, 2, 3, 4]))
      [(1, 2), (2, 3), (3, 4)]
      """
      return zip(*(collections.deque(itertools.islice(it, i), 0) or it
                 for i, it in enumerate(itertools.tee(seq, n))))



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: