I wanted to make a list of empty sets for my program. This works for making a list of unique zeros.
x=5
l=[0]*x
print(l)
m[0]=1
#[1,0,0,0,0]
If you try the same with sets or a list of list it doesn't work.
x=5
l=[set()]*x
l[0].add(1)
print(l)
#[{1},{1},{1},{1},{1}]
The same happens with lists.
x=5
l=[[]]*x
l[0]+=[1]
print(l)
#[[1],[1],[1],[1],[1]]
The only work around I've found is using range(). My question is there a different way of doing this I don't know about? It seems like I'm missing something.
x=5
l=[[] for i in range(x)]
l[0].add(1)
print(l)
#[[1],[0],[0],[0],[0]]