1

I've noticed something strange when trying to implement elements of a 2d list in python. Here is my code

n_dk=2*[5*[0]]
n_dk[0][0]+=1
print n_dk

I would expect the output to be

[[1,0,0,0,0],[0,0,0,0,0]]

but the actual output is

[[1,0,0,0,0],[1,0,0,0,0]]

can anyone tell me what I am doing wrong. btw I used a numpy array instead and it worked the way I wanted it to.

user1893354
  • 5,778
  • 12
  • 46
  • 83
  • 1
    This question is asked *many* times. See http://stackoverflow.com/questions/1959744/python-list-problem – arshajii Sep 06 '13 at 15:00

0 Answers0