LearnPy Hub
← Iterators & Generators problems
Medium

Chunk Generator

Write a generator chunks(items, k) yielding lists of k items (the last may be shorter). Print each chunk on its own line.

Input

A line of items, then k.

Output

One line per chunk.

Sample 1

Input
a b c d e
2
Output
a b
c d
e

Sample 2

Input
1 2 3
3
Output
1 2 3
solution.py
Output appears here
Chunk Generator · Python practice problem · LearnPy Hub