[Python-ideas] Proposal to change List Sequence Repetition (*) so it is not useless for Mutable Objects
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue May 31 08:55:37 EDT 2016
> On 31.05.2016 07:27, Matthew Tanous wrote:
>>
>>arr = [[True] * 5] * 5
>>
>>This does not create a matrix-like arrangement of the immutable truth
>>variable, but instead creates a list of 5 references to the same list
I think this would be better addressed by an extension
to list comprehensions, e.g.
arr = [[True times 5] times 5]
where
[x times n]
would be equivalent to
[x for i in range(n)]
Since this would evaluate x afresh for each elment, it
would avoid all the thorny issues involved in trying to
automatically deep-copy arbitrary objects.
--
Greg
More information about the Python-ideas
mailing list