I'm asked to write a function rotate_left3(nums)
that takes a list
of ints of length 3 called nums
and returns a list
with the elements "rotated left" so [1, 2, 3] yields [2, 3, 1].
The questions asks to rotate lists of length 3 only. I can easily do this by the following function (as long as the lists will only be of length 3):
def rotate_left3(nums):
return [nums[1]] + [nums[2]] + [nums[0]]
However, my question is, how do I do the same operation but with lists of unknown lengths?
I have seen some solutions that are complicated to me as a beginner. so I'd appreciate if we can keep the solution as simple as possible.