osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

List replication operator


On Thu, 24 May 2018 11:24:41 -0700, Rob Gaddi wrote:

> On 05/24/2018 11:17 AM, 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.
>> 
>> 
>> Thoughts?
>> 
>> 
>> 
>> 
> I think the same people making that mistake now would still do so
> because they didn't know they needed the special operator.

People aren't born knowing that * is usable with lists, so the fact that 
they won't be born knowing about ** either is not a point against it.

Wherever newbies are learning about * will soon teach them to use ** for 
multi-dimensional lists as well.

> [[] for _ in range(5)] works just as well without adding more syntax.

This doesn't add more syntax. ** is already valid syntax. It is just 
adding a new method to sequences.

For newbies, using a list comp is not obvious or easily discoverable.


-- 
Steve