Can't shift the origin in python..? -


a=[3,4] b=[5,8] c=[7,4] d=[a,b,c] print (d) in range(3):     j in range(2):           d[i][j]-=a[j]   print (d) 

in python code output is

[[0,0], [5,8], [7,4]] 

instead of

[[0,0], [2,4], [4,0]] 

can tell me why?

d contains reference of a, not copy.

a changes [3,4] [0,0] during first iteration of loop. that's why, next iteration of loop d[i][j]-=[0,0].

you should replace d=[a,b,c] d = [list(a), b, c]


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -