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

Michael Selik mike at selik.org
Thu Jun 14 22:51:24 EDT 2018

Sorry, I forgot that you dropped the suggestion to make it an insert
operator and are only asking for an append operator.

I see no benefit to this, because += already is an elegant way to extend a
list, which is more flexible than append. Yes, if the right-hand is an
iterable and should be appended as a single element, you'll need to enclose
it in a single-element container. This is true for strings, lists, sets,
whatever. It's natural and is not a "trick".

If you would like to prove the need for this operator, one piece of
evidence you can provide is a count of the number of times someone writes
"list.append" for an iterable vs "+=" and encloses a str or other type in a
throw-away list to effectively append.

If the latter habit is common, that's evidence that the language may need
to be improved. Why don't you search GitHub projects to collect some

On Thu, Jun 14, 2018, 7:40 PM Michael Selik <mike at selik.org> wrote:

> On Thu, Jun 14, 2018, 7:24 PM Mikhail V <mikhailwas at gmail.com> wrote:
>> what haven't we repeated in this thread yet? Motivation was explained.
> You have repeated your explanations a few times. It isn't convincing.
> It seems to me that your main complaint is that strings are iterable,
> though you haven't expressed it as such. During slice assignment, you're
> surprised that the string is a sequence of characters. I understand, but I
> don't find that confusion a compelling reason to add a new operator.
> About confusion probably haven't discussed : so Xor ^ works on sets,
>> IIRC for finding
>> union without common elements.
> I wrote about this in an earlier email, which you didn't reply to. You're
> correct that xor doesn't make sense with lists, especially not between a
> list and a single element.
> Again, though other operators have been given different meanings in
> special contexts, those decisions should be seen as abnormal, not an excuse
> to keep creating more special cases.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180614/d378cb1a/attachment-0001.html>

More information about the Python-ideas mailing list