Oct-19-2020, 09:18 PM
Your first line has not made a list of 5 different lists inside, it's made a list with 5 copies of the same list inside.
>>> l = [[]] * 5 >>> l [[], [], [], [], []] >>> [id(x) for x in l] [4464943816, 4464943816, 4464943816, 4464943816, 4464943816]Instead you want to create a new list 5 different times. Perhaps:
>>> l = [[] for i in range(5)] >>> l [[], [], [], [], []] >>> [id(x) for x in l] [4464944008, 4464944648, 4464944456, 4464944328, 4464944200] >>> l[2].append(3) >>> l [[], [], [3], [], []]