[issue27135] nested list produced with multiplication is linked to the same list

2016-05-27 Thread Emanuel Barry
Emanuel Barry added the comment: You do raise a valid point, sequence repetition (*) on lists of mutable objects serves very little purpose. However, as I stated, it is a side-effect of the data model and changing it would be yet another special case, which aren't special enough to break the

[issue27135] nested list produced with multiplication is linked to the same list

2016-05-27 Thread Matthew Tanous
Matthew Tanous added the comment: It makes sense, except for this case is not true when "x" is an immutable data type - it appears as though something like [5] * n creates a list of totally separate elements (even if they start as the same thing). It is difficult to see a case where I would

[issue27135] nested list produced with multiplication is linked to the same list

2016-05-27 Thread Emanuel Barry
Emanuel Barry added the comment: The reason why Python behaves like that in this case is a side-effect of the way the data model is implemented. Lists are a mutable data type, which means that referencing the same list - which is what you are doing - as opposed to creating a new one each

[issue27135] nested list produced with multiplication is linked to the same list

2016-05-27 Thread Matthew Tanous
Matthew Tanous added the comment: I'm aware that it's how Python works at present. My point was that this is awkward and counter-intuitive, with no purpose I can see worth serving. "That's just how it works" seems to me a rather insufficient answer, especially for such a seemingly trivial

[issue27135] nested list produced with multiplication is linked to the same list

2016-05-26 Thread Benjamin Peterson
Benjamin Peterson added the comment: That's just how Python works. https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list -- nosy: +benjamin.peterson resolution: -> not a bug status: open -> closed ___ Python tracker

[issue27135] nested list produced with multiplication is linked to the same list

2016-05-26 Thread Matthew Tanous
New submission from Matthew Tanous: 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