Steven D'Aprano schrieb am 25.05.2018 um 04:25:
> On Thu, 24 May 2018 15:12:09 -0400, Ned Batchelder wrote:
> 
>> On 5/24/18 2:17 PM, Steven D'Aprano wrote:
> [...]
>>> But what do people think about proposing a new list replication with
>>> copy operator?
>>>
>>>      [[]]**5
>>>
>>> would return a new list consisting of five shallow copies of the inner
>>> list.
>>>
>> "shallow" will be the next problem.  Do we also need this?:
>>
>>      [[[]]]***5             # j/k
> 
> You might be right: on further thought, I think I want deep copies, not 
> shallow.

But how would that protocol work then? What would happen with a data
structure like this:

    [( 1, [1, 2, 3] )] ** 3

? Would it also deep copy the tuple, or ignore it? What about other,
non-builtin sequence types? The '**' operator cannot just recursively call
'**' on the items in the list, because they may not support it. Or they may
support it, but not in the expected way.

And limiting this to lists of lists seems rather arbitrary. What about
subtypes of lists?

Calling "copy.deepcopy()" internally instead of a recursive '**' doesn't
seem safe either, because it also wouldn't know where to stop.

Stefan

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to