List replication operator
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu May 24 21:28:56 EDT 2018
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
More information about the Python-list
mailing list