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

Chris Angelico rosuav at gmail.com
Wed Jun 13 10:13:01 EDT 2018


On Thu, Jun 14, 2018 at 12:04 AM, Mikhail V <mikhailwas at gmail.com> wrote:
> On Wed, Jun 13, 2018 at 2:15 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Mikhail V wrote:
>>>
>
>> My feeling is that inserting is not a frequent enough operation
>> to warrant having its own operator, especially not when there
>> is already a syntax that does the same thing.
>
> Depends on what you count as 'insert' - append is one case of insert ;)
> (logically seen)
>
> Sorry for repeating myself, the idea was that the default meaning is append(),
> i.e. normal operator usage on list:
>
> L1 = L2 ^ item        - would be same as
> L1 = L2.append(item)

Not sure exactly what your intention here is, because list.append
mutates the list and returns None. Does "L2 ^ item" mutate L2 in
place, or does it construct a new list? If it mutates in place, does
it return the same list? Or if doesn't, how is it different from "L2 +
[item]", which is a much more logical spelling of list addition?

ChrisA


More information about the Python-ideas mailing list