Rotate a List
Completed
Read a line of items and an integer k. Rotate the list right by k places (the last k items move to the front) and print it.
Input
Line 1: items. Line 2: k ≥ 0 (may be larger than the list).
Output
The rotated items on one line.
Example
Input
1 2 3 4 5 2
Output
4 5 1 2 3
Editor
Python
Hints
k % len(items) handles k larger than the list.
items[-k:] + items[:-k] rotates right by k.
Solution explanation
Slicing builds the rotated list in one expression. The if k guard is needed because items[-0:] is the whole list.
Show solution
items = input().split()
k = int(input()) % len(items)
print(*(items[-k:] + items[:-k] if k else items))