Apologies if this has been answered somewhere else. I've searched stack overflow but could not find an answer to this problem.
i do not understand why list L1 is modified even after i create a temp list and put the new rows in there and assign it to list L2.
As far as i can see, i am not copying any list beside temp_list so there should be no link in memory to list L1.
Thanks in adavance
>>> L1 = []
>>> a = ['this','is','a','test','message']
>>> L1.append(a)
>>> b = ['this','is','another','good','message']
>>> L1.append(b)
>>> print (L1)
[['this', 'is', 'a', 'test', 'message'], ['this', 'is', 'another', 'good',
'message']]
>>> list_copy_L1 = L1[:]
>>> L2 = []
>>> temp_list = []
>>> for row in list_copy_L1:
if row[3] == 'good':
row[3] = 'BAD'
temp_list.append(row)
>>> L2 = temp_list[:]
>>> print (L1)
[['this', 'is', 'a', 'test', 'message'], ['this', 'is', 'another', 'BAD',
'message']]
>>> print (L2)
[['this', 'is', 'a', 'test', 'message'], ['this', 'is', 'another', 'BAD',
'message']]
>>>