List replication operator
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri May 25 07:45:51 EDT 2018
On Fri, 25 May 2018 11:48:49 +0100, Ben Bacarisse wrote:
> Another way of looking at it would be in terms of evaluation rather than
> copying. [<stuff>] evaluates to a new list object, so if there were an
> alternate version of L * n (for the sake of argument L ** n) that
> evaluated the list expression n times to make the new list you would
> also get the behaviour you want.
The problem is, the * operator doesn't seen the expression "[]" it sees
the object. So there's no way of delaying the evaluation of the [] until
after the * operator is called in current Python, nor any way of telling
it when to evaluate the expression.
It would require special syntax, like the lambda syntax delays evaluation
of the expression and returns a function, instead of evaluating the body
of the function at the point of definition.
I'm not interested in adding a special case to the interpreter just for
this specific issue. If there was a way to delay arbitrary expressions in
arbitrary places for arbitrary uses, that would be interesting to
consider, but to limit it to "list ** count" is not.
--
Steve
More information about the Python-list
mailing list