Message266475
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. |
|
Date |
User |
Action |
Args |
2016-05-27 05:25:00 | Matthew Tanous | set | recipients:
+ Matthew Tanous |
2016-05-27 05:25:00 | Matthew Tanous | set | messageid: <1464326700.96.0.464435009997.issue27135@psf.upfronthosting.co.za> |
2016-05-27 05:25:00 | Matthew Tanous | link | issue27135 messages |
2016-05-27 05:25:00 | Matthew Tanous | create | |
|