List replication operator

bartc bc at freeuk.com
Fri May 25 08:58:03 EDT 2018


On 25/05/2018 13:46, Chris Angelico wrote:
> On Fri, May 25, 2018 at 10:36 PM, bartc <bc at freeuk.com> wrote:
>> On 24/05/2018 19:17, 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?
>>
>>
>> Choice of ** doesn't seem right for a start, as it suggests it should mean
>> []*[]*[]*[]*[], which it doesn't. (Apparently []*2 /is/ the same as []+[].)
>>
> 
> We've already had a suggestion for [[]]@5 and that should deal with
> that issue.

I'm in general not in favour of piling in special symbols into a 
language just to solve some obscure or rare problem.

As I went on to demonstrate, function-like syntax (or even actual 
functions) could do that job better, by describing what the operation 
does and not leaving people scratching their heads so much when they 
encounter that funny-looking operator hidden in 20,000 lines of code.

As for '@', if a variable name can come before it /and/ after it, and 
either or both can be dotted, wouldn't that cause it to be highlighted 
as an email address in many circumstances? Such as in code posted here.

(OK, let's try it and see what happens. My Thunderbird doesn't do 
previews so I will have to post it first:

    abc at def
    abc at def.ghi)

I would find that rather annoying.

-- 
bartc



More information about the Python-list mailing list