This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Matthew Tanous
Recipients Matthew Tanous
Date 2016-05-27.05:25:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464326700.96.0.464435009997.issue27135@psf.upfronthosting.co.za>
In-reply-to
Content
If I produce a list in this fashion:

l = [[x] * n] * n

I would expect that I would obtain a matrix-like structure.  Instead, I get a list of the *same* list, such that the statement:

l[x][y] = z

would change, in essence, every value in "column" y.  This is different from the case where the list contains a string or integer value, where the new list points to separate instances of the internal values.

In my view, this is strange and counter-intuitive behavior.  If I want to create a matrix-like set to None to start, instead of using:

 mat = [[None] * N] * N

I have to use:

 mat = [[None] * N for i in range(N)]

If there is any possibility for it to be changed, I think that would improve things considerably.  In almost no cases, in my opinion, would I want a list of lists that are forced to be the same.
History
Date User Action Args
2016-05-27 05:25:00Matthew Tanoussetrecipients: + Matthew Tanous
2016-05-27 05:25:00Matthew Tanoussetmessageid: <1464326700.96.0.464435009997.issue27135@psf.upfronthosting.co.za>
2016-05-27 05:25:00Matthew Tanouslinkissue27135 messages
2016-05-27 05:25:00Matthew Tanouscreate