[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Jaap Woldringh
Jaap Woldringh added the comment: Op 17-01-2020 om 14:03 schreef Karthikeyan Singaravelan: > Karthikeyan Singaravelan added the comment: > > You're referencing to the same list 3 times in B. So modifying it once means > all the elements referring to same object reflect the change. Make a copy

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Ezio Melotti
Ezio Melotti added the comment: See also https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x You can use the builtin function id() to see the id of the lists, and verify whether they refer to the same object or not. -- nosy: +ezio.melotti

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: You're referencing to the same list 3 times in B. So modifying it once means all the elements referring to same object reflect the change. Make a copy of the list during append to ensure modification of one doesn't affect other. This is not a

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Jaap Woldringh
New submission from Jaap Woldringh : Python used: Python 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. In Ubuntu 18.04.3 But in any other version of Python3, and Python2, that I tried, the behaviour of a