Rotating a list to the right

Write code · Challenge · §3.3, §5.1, §8.2 Giving back

Complete the function rotate_array, which returns a new list made by rotating a list to the right k times. One rotation moves every value one place to the right, and the last value comes to the front. rotate_array([1, 2, 3, 4, 5], 2) is [4, 5, 1, 2, 3]. Do not change the original list.

Starter code

def rotate_array(nums, k):
    # Write your code here
    pass

print(rotate_array([1, 2, 3, 4, 5], 2))

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.