20 Feb
2016
20 Feb
'16
11:34 p.m.
I do not know whether to call this a BUG because it seems obviously intended.. but totally undocumented and unexpected.. I am new to Python and this was a major problem, waste of time and gave logic errors which were difficult to trace.. mylist = [[1,2],[3,4],[5,6],[7,8]] # matrix or list of lists temp = mylist[0] mylist[3] = temp print(mylist) [1,2], [3,4], [5,6], [1,2] # Now modify mylist[3] mylist[3][1] = 0 print(mylist) [1,0],[3,4],[5,6],[1,0] Note mylist[0] and mylist[3] are pointers to the same data so when I thought I was copying a list item Python did not make a true copy.. Nothing in the docs I read said anything about this.. regards *Mike Bellamy* *Keep Calm and Carry On*
3238
Age (days ago)
3238
Last active (days ago)
0 comments
1 participants
participants (1)
-
Mike Bellamy