Sliding Windows over Any Iterable

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 9. Everything before it counts as cleared.

Implement windowed(iterable, n, step=1), a generator of tuples of n consecutive items, advancing step items each time. It must work on infinite and one-shot iterators, holding at most n items in memory (use collections.deque(maxlen=n)).

Don't yield a final short window. If the input is shorter than n, yield nothing.

Then implement pairwise_diffs(iterable): a generator of differences between consecutive items, built on windowed.

#iterators#generators#itertools2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Sliding Windows over Any Iterable · TechGradify