I was looking at different discussions for this LeetCode problem, (basically, we need to remove all instances of a given value in an array, without creating or using another array) and I came across this particular solution:
def removeElement(self, nums, val):
start, end = 0, len(nums) - 1
while start <= end:
if nums[start] == val:
nums[start], nums[end], end = nums[end], nums[start], end - 1
else:
start +=1
return start
I don't understand what is happening in this line:
nums[start], nums[end], end = nums[end], nums[start], end - 1
This comma syntax is unfamiliar to me. I have searched in the Python docs and here in Stack Overflow and learned that in Python, separating elements with commas produces a tuple, but for the life of me, I don't understand if that's what's happening here, since the "newly created tuple" is not being assigned to anything (there's even an assignment statement in there). Unless this has nothing to do with tuples and something else entirely is happening here.
I would like help understanding this line.