I can create a 2D array in python 3 ways:
#1 10 rows 2 column
arr2d = [[0]*2]*10
#2 10 rows 2 column
arr2d_2 = [[0,0]] *10
#3 10 rows 2 column, using list comprehension **internal [] missing in OP
arr2d_list = [[0 for j in xrange(2)] for i in xrange(10)]
Why is it that for #1 and #2, when I assign a value to a specific row and column of the array, it's assigning the value to all the columns in every row? for example
arr2d[0][1]=10
arr2d
[[0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10]]
arr2d_2[0][1]=10
arr2d_2
[[0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10]]
but for #3, it assign value to only specific row and columns
arr2d_list[0][1]=10
arr2d_list
[[0, 10], [0, 0], [9, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
Why is it behaving this way?