List replication operator

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 24 22:25:08 EDT 2018


On 2018年5月24日 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.
Originally I thought that deep copies was an YAGNI. Have you *ever* seen 
anyone complain that * didn't make a deep copy of the list contents? I 
never have. But then I realised that if this works, people will surely 
try to use it to make three-dimensional lists as well as two, and for 
that we need deep copies.
-- 
Steve


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /