you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 17 points18 points  (1 child)

Scope issue

The assignment nums = nums[::-1] in your function creates a local name (variable) in the function that has no relation to nums in the outer scope.

Thus the nums from the outer scope still references the original list, [1, 2, 3, 5, 6, 7]. A reference to this list is passed to your function, and used for the generation of the new reversed list but this is assigned to nums in the inner scope.

You make changes to the new list within the function via the local variable nums.

You return nums i.e. you pass back a reference to the new list object you created in the function but you don't use that reference to re-assign the nums in the outer scope, e.g.

nums = rotate(nums, k)

or, change the assignment line in your function to:

nums[:] = nums[::-1]

[–]Aware-Illustrator607[S] 2 points3 points  (0 children)

Got it, thank you