Matthew Tanous <mtanous22@...> writes:
It is my opinion that the sequence repetition operator should be modified to make copies of the objects it is repeating, rather than copying references alone. I believe this would both be more intuitive from a semantic point of view and more useful for the developer.
This would change the operator in a way that is mostly unseen in current usage ( * 3 would still result in [5, 5, 5]) while treating mutable nesting in a way that is more understandable from the apparent intent of the syntax construction.
I agree that when I was starting out with python this tripped me up a couple of times but Marc-Andre pointed out it is not necessarily easy to solve in a generic way.
As a point of reference, I currently tend to do this via generators arr = list(Foo() for i in range(5)) or list comprehensions arr = [Foo() for i in range(5)]
note that this works for the mutable and immutable case.
Kind Regards, Lorenz