[Python-ideas] Operator for inserting an element into a list
mike at selik.org
Tue Jun 12 15:25:30 EDT 2018
On Tue, Jun 12, 2018 at 11:08 AM Mikhail V <mikhailwas at gmail.com> wrote:
> On Tue, Jun 12, 2018 at 7:42 PM, Clint Hepner <clint.hepner at gmail.com>
> So the idea was about an insert/append operator.
> Which would use augmented operator. The operator may be
> /= or ^=. (I like ^= more, so I'll put here example with it).
The "/" operator means divide. How do you divide a list?
The "^" operator means exclusive-or. Again, strange concept for a list.
Yes, there are examples of Python (mis)using operators like "%" for string
interpolation. Note the difficulties that caused; we now have 3 ways to
interpolate. It looked cool at the time, but happily we have f-strings now.
> L += var
> L = L + var
> are different, so it seems to me they were not meant to be
> bound together.
One is mutation, the other isn't, but aside from that, the result is
> If the intention is to insert an element, indeed it is confusing, for
> me at least:
> L[0:0] = "bb"
> -> ["b","b","aa"]
Thats, like, just your opinion, Man. Kidding aside, I think you'll find
it's natural once you get used to slice assignment. The slice assignment
iterates over the right-hand argument and inserts each element. It
overwrites the existing slice if any.
In this example, you've mixed issues. It looks like you've gotten confused
by string iteration. When you loop a string, you get 1-len strings.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas