Possible Duplicate:
Unexpected feature in a Python list of lists
How to initialize a two-dimensional array in Python?
I wanted to create a nested list of nsize and then append items into it one by one according to a criterion.
For this I wrote it like following ( nsize = 4 )
a = [[]] * 4 # which creates on display a = [ [] , [] , [] , [] ]
Now I do something like this a[1].append(3)
which gives me the output [[3], [3], [3], [3]]
What am I doing wrong here ? Should'nt only the 2nd list ( a[1] ) be updated with the value 3 ?