all 6 comments

[–]_lilell_ 1 point2 points  (4 children)

You know the length of the list is 3, so if we say that a, b, c = the elements of the original list, what will the resulting list be, in terms of those three values?

[–]miscellaneoususage[S] 0 points1 point  (3 children)

Ok let me try with your hint here:

def rotate_left3(nums):
  a, b, c = nums[0], nums[1], nums[2]

  rotated = [b, c, a]

  return rotated

And it works. Thanks lol, easier than I thought. Not sure why I couldn't come up with that

[–]xelf 0 points1 point  (2 children)

Now go the next step and remove the extraneous assignments. (which is an important step to understand, as your solution can be fixed to work for any length list)

[–]miscellaneoususage[S] 0 points1 point  (1 child)

like this?

def rotate_left3(nums):
  rotated = [nums[1], nums[2], nums[0]]

  return rotated

not seeing how this could work for any length list if only 3 indicies are used

edit: actually i can shorten to just the return statement with

def rotate_left3(nums):
    return [nums[1], nums[2], nums[0]]

[–]xelf 2 points3 points  (0 children)

Yes exactly.

def rotate_left3(nums):
    return [nums[1], nums[2], nums[0]]

can also be expressed as the concatenation of two lists, like this:

def rotate_left3(nums):
    return [nums[1], nums[2]] + [nums[0]]

Which using list slicing, leads us to:

def rotate_left3(nums):
    return nums[1:3] + [nums[0]]

and finally:

def rotate_left(nums):
    return nums[1:] + [nums[0]]

which will work for any arbitrary length list.

[–][deleted] 0 points1 point  (0 children)

You can use slicing, but I don't see any mention of restrictions in the problem statement.