On Wed, Jul 11, 2018 at 10:55 AM Peter Otten <__pete...@web.de> wrote:
As to why you'd expect that one I've no idea
my mistake
--
Abdur-Rahmaan Janhangeer
https://github.com/abdur-rahmaanj
Mauritius
--
https://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
> a = [[1]] * 7
>
> creates a list containing seven references to the same inner list [1].
I. e. it is roughly equivalent to
b = [1]
a = [b, b, b, b, b, b, b]
--
https://mail.python.org/mailman/listinfo/python-list
Abdur-Rahmaan Janhangeer wrote:
> saw this snippet on the internet : why assigning by index propagates it
> all?
It doesn't.
>
a = [[1]] * 7
a
> [[1], [1], [1], [1], [1], [1], [1]]
> >>> a[0][0] = 2
a
> [[2], [2], [2], [2], [2], [2], [2]]
>
> why not
>
> [[1], [2], [2], [2], [