Convert list to another form but providing same information

Maurice mauricioliveiraguarda at gmail.com
Mon Mar 21 14:30:48 EDT 2016


Just figured why:

If I type this on the kernel:

weirdList = [[0]*3]*5

weirdList
Out[257]: [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

weirdList[0][0] = 1

weirdList
Out[259]: [[1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]]

All first elements of the sublists also changes. I dunno why...



More information about the Python-list mailing list