Rotate a list
A rotation moves items off the right end and back in at the left. Rotating [1, 2, 3, 4] right by one gives [4, 1, 2, 3].
rotate_right([1, 2, 3, 4], 1)
# [4, 1, 2, 3]
rotate_right([1, 2, 3], 4)
# [3, 1, 2]Things to clarify
kcan be larger than the list. Rotating a list of lengthnbynchanges nothing, so only the remainder matters.kcan be zero, and the list can be empty.- Return a new list, leaving the input as it was.
Look out for items[-0:]. Since -0 equals 0, that slice is the whole list and not an empty one. This is a common source of bugs in slice-based answers.
Your task
Write rotate_right(items, k) returning a new list rotated right by k places, where k is 0 or more.
The explanation opens here once every check passes.