Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Understanding lists of lists [duplicate]

$
0
0

Consider the following code:

a = [[]] * 3a[1].append("foo")

I would expect the value of a to become:

[[], ["foo"], []]

instead, every element of a is updated:

[["foo"], ["foo"], ["foo"]]

Why?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>