Chunk a List

Lab Python Intermediate 20 points

Read a line of items and a size k. Split the items into groups of k (the last group may be shorter) and print each group on its own line.

Input

Line 1: items. Line 2: k ≥ 1.

Output

One line per group.

Example

Input

1 2 3 4 5 6 7
3

Output

1 2 3
4 5 6
7
Sample input available Sample output available
Editor
Python

Hints

range(0, len(items), k) gives the start index of each group.

Solution explanation

Slices that run past the end are simply cut short, which handles the last group.

Show solution
items = input().split()
k = int(input())
for i in range(0, len(items), k):
    print(*items[i:i + k])
Output
Answer
HOME LEARN COMMUNITY DASHBOARD