I have an issue where when I append a 1D list multiple times as rows to a 2D list, subsequent changes to the 2D list affect all rows. This thread (Python list confusion) cleared up why this is the case - basically each row is the same sub-list or object so a change to that sub-list changes every row in the 2D list. However, I don't know how to fix it. Here is my example:
NumOfRows = 100
LanesToCheck = [0, 1, 2, 3]
Lanes = []
for j in range(0,NumOfRows):
Lanes.append(LanesToCheck)
LanesToCheck is used to initialize each row and the idea is that the user of my script can just change this 1D list in an easy code location and the entire 2D array is initialized with it. I know I can just use:
Lanes.append([0, 1, 2, 3])
but I'd like to have this LanesToCheck constant easily accessible to the user. Is there a way to initialize my 2D array using this 1D array in a way that each row is a separate entity?