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

Mikhail V mikhailwas at gmail.com
Thu Jun 14 13:37:08 EDT 2018


On Thu, Jun 14, 2018 at 7:40 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> On Wed, Jun 13, 2018 at 6:45 PM, Mikhail V <mikhailwas at gmail.com> wrote:
>>

> So it would be nice to have an operator version of append -- but given the
> limited number of operators, and their usual uses, I suspect it would cause
> even more confusion...
>
> But throwing it out there, how about (ab)using the mat_mul operator:
>
> a_list @= an_item
>


Yes, none of the oprators fits well by sense.
But which symbol would fit here if you could choose *any* symbol?


I've picked the caret ^ for two reasons:
1. It is originally associated with the insertion mark.
>From wikipedia (https://en.wikipedia.org/wiki/Caret):
"The caret was originally used, and continues to be, in
handwritten form as a proofreading mark to indicate
where a punctuation mark, word, or phrase should be
inserted in a document."

So there is some relation with "insert" operation.
But of course this makes sense mainly for people who have
some editorial or typography background, (such as myself).
So for me it makes perfect sense.

2. The symbol ^ itself looks quite 'gentle' and to my eye, is not too
 distracting (at least less than some other operators).
So e.g. I find that vertical bar | causes some bad eye straining effect.



> Another note:
>
> One of the major motivations for augmented assignment was being able to
> support in-place operations for numpy:
>
> an_array += something
>
> which was MUCH nicer notation that was was required:
>
> np.sum(an_array, something, out=an_array)
>
> That is a much bigger win than going from .append() to an operator.
>

Agreed.


More information about the Python-ideas mailing list