Skip to content

Commit

Permalink
Add note about padding with windowed
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles committed Jan 23, 2019
1 parent 73d7498 commit c5088d2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions more_itertools/more.py
Expand Up @@ -658,6 +658,15 @@ def windowed(seq, n, fillvalue=None, step=1):
>>> list(windowed([1, 2, 3, 4, 5, 6], 3, fillvalue='!', step=2))
[(1, 2, 3), (3, 4, 5), (5, 6, '!')]
To slide into the iterable's items, use :func:`chain` to add filler items
to the left:
>>> iterable = [1, 2, 3, 4]
>>> n = 3
>>> padding = [None] * (n - 1)
>>> list(windowed(chain(padding, iterable), 3))
[(None, None, 1), (None, 1, 2), (1, 2, 3), (2, 3, 4)]
"""
if n < 0:
raise ValueError('n must be >= 0')
Expand Down

0 comments on commit c5088d2

Please sign in to comment.