[issue43157] Bug in methods of creating the 2d list

Steven D'Aprano report at bugs.python.org
Sun Feb 7 15:50:05 EST 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

There is also an FAQ about this:

https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list

See also:

https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x

By the way, for future bug reports, please take the time to make a *minimal* example please:

http://www.sscce.org/

https://stackoverflow.com/help/minimal-reproducible-example

In this case a minimal example would be:

    mylist = [[0]]*2
    mylist[0][0] = 1
    print(mylist)  # expect [[1], [0]] but get [[1], [1]]

Thank you.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43157>
_______________________________________


More information about the Python-bugs-list mailing list