I am building a list of lists. I am reading the elements from an input file. I am reading in each line in the file as a string-single-element to a sub-list in the list. First, I created the list of lists:
>>> b = [[]] * 5
However, when I tried to append an item, I got the following:
>>> b[1].append("abc")
>>> b
[ ['abc'], ['abc'], ['abc'], ['abc'], ['abc'])
Why does append
change all the sub-lists? Is insert()
better in this situation?