[Python-ideas] Operator for inserting an element into a list

Mikhail V mikhailwas at gmail.com
Wed Jun 13 16:21:39 EDT 2018


On Wed, Jun 13, 2018 at 5:46 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Jun 14, 2018 at 12:40 AM, Mikhail V <mikhailwas at gmail.com> wrote:

>> L1 = L2 ^ item
>> is
>> L1 = L2 + [item]
>>
>> and
>> L ^= item
>> is
>> L.append(item)
>> or
>> L += [item]
>
> Okay. Now it all is coherent and makes perfect sense... but you're
> offering alternative spellings for what we can already do. The only
> improvement compared to the + operator is that you don't need to
> surround the operand in brackets; in return, it's less general, being
> unable to add multiple elements to the list. The only improvement
> compared to .append is that it's an operator. There's no connection to
> exclusive-or, and there's not a lot of "but it's intuitive" here (cf
> Path division).

Exactly, IMO it's important to make distinction for the item append.
Not only for practical reason, but for semantical distinction, just
like append() vs extend() distinction.
Otherwise if += is used as append(), it creates an
illusion that += _is_ append().


More information about the Python-ideas mailing list