On 31.05.2016 13:39, Lorenz wrote:
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.
I can only agree here. Even today, despite knowing the fact, it's causing some headaches in some cases.
However, I think that's the reason why it's not so easy to do in a general manner.
Maybe, somebody has a good idea how to.
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