<p>I created a list of lists:</p>
<pre><code>xs = [[1] * 4] * 3

# xs == [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]  
</code></pre>
<p>Then, I changed one of the innermost values:</p>
<pre><code>xs[0][0] = 5

# xs == [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]  
</code></pre>
<p>Why did every first element of each sublist change to <code>5</code>?</p>

```
```
[[1] * 4] * 3
```
```
or even:
```
```
[[1, 1, 1, 1]] * 3
```
```
Creates a list that references the internal
```
[1,1,1,1]
```
3 times - not three copies of the inner list, so any time you modify the list (in any position), you'll see the change three times.
It's the same as this example:
```
```
>>> inner = [1,1,1,1]
>>> outer = [inner]*3
>>> outer
[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
>>> inner[0] = 5
>>> outer
[[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]
```
```
where it's probably a little less surprising.