[Python-ideas] Operator for inserting an element into a list
Mikhail V
mikhailwas at gmail.com
Wed Jun 13 10:40:09 EDT 2018
On Wed, Jun 13, 2018 at 5:13 PM, Chris Angelico <rosuav at gmail.com> wrote:
> 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:
>> 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?
I made wrong example again. So
L1 = L2 ^ item
is
L1 = L2 + [item]
and
L ^= item
is
L.append(item)
or
L += [item]
More information about the Python-ideas
mailing list