Can anyone explain to me why on test1, nums is [[0,0],[-1,-1],[0,0],[0,0]] but not on test2? as my understand python for xx in xxx is pretty much like for loop in any other language and take element by element. So what is different between using unpack in for loop and not? Thank you
test([[0,0],[0,0],[0,0],[0,0]])
test2([[0,0],[0,0],[0,0],[0,0]])
def test1(self, nums):
ctn = 0
for e in nums:
ctn += 1
u, v = e
if ctn == 2:
e[0] = e[1] = -1
print(nums) #[[0,0],[-1,-1],[0,0],[0,0]]
def test2(self, nums):
ctn = 0
for u, v in nums:
ctn += 1
if ctn == 2:
u = v = -1
print(nums) #[[0,0],[0,0],[0,0],[0,0]]