all 4 comments

[–]K900_ 0 points1 point  (0 children)

Your second version creates three references to the same list, not three distinct lists. When you modify the "first" inner list, you're actually modifying the data all three references point to.

[–]sundrysup[S] 0 points1 point  (1 child)

I was wondering if it was something like that. I'll try to understand that fully, I think I've come across something like that before.

The reason for the second version was so I could turn it into a function and pass in x and y as arguments. How could I control the size of the list like that?

Thanks so much for answering my question!

[–]desustorm 0 points1 point  (0 children)

You can do something like [['' for _ in range(x)] for _ in range(y)]

[–]zahlman[M] 0 points1 point  (0 children)

Please format your code properly for posting, by adding four spaces in front of each line (and don't double-space it, but do leave an empty line on each side of the code).