LearnPy Hub
← Iterators & Generators problems
Medium

Sliding Windows

Write a generator windows(items, k) yielding every block of k neighbouring items as a tuple. Read numbers and k; print each window on its own line.

Input

Numbers; then k.

Output

Lines.

Sample 1

Input
1 2 3 4
2
Output
(1, 2)
(2, 3)
(3, 4)

Sample 2

Input
5 6 7
3
Output
(5, 6, 7)
solution.py
Output appears here
Sliding Windows · Python practice problem · LearnPy Hub