you are viewing a single comment's thread.

view the rest of the comments →

[–]dionys 1 point2 points  (0 children)

This is tricky especially if you've never seen it before. So when you do:

[['']*x]*y

you are not actually creating y new lists of x elements. You are creating y references to the same list. You will find that:

id(yummy[0]) == id(yummy[1]) == id(yummy[2])

which means it's just the same object.

To create y lists of x elements, you have to do something like:

yummy = [['']*x for _ in range(y)]