First I have initialized mylist as follows :
buf = []
mylist = []
for i in range(0, 10):
mylist.append(buf)
Now mylist is like this :
mylist:
[[], [], [], [], [], [], [], [], [], []]
Now when I want to append a value to the first index like so:
mylist[0].append(3)
And I print mylist again I get this:
[[3], [3], [3], [3], [3], [3], [3], [3], [3], [3]]
Where it should only add the number 3 to the first list inside mylist as so:
[[3], [], [], [], [], [], [], [], [], []]
What is wrong with my code? when I don't use the above for loop to create embedded lists and I do it manually, I don't have this problem. And I need to do by using for loop because I need a huge embedded list, I put 10 there just for the sake of simplicity.