On Wed, Jun 13, 2018 at 6:45 PM, Mikhail V <mikhail...@gmail.com> wrote:

> Another point is that people do like augmented operators much and for the
> append - there are so many advises like: hey, use L += [item] !
>

another data point -- in teaching, a number of newbie students do exactly
that.

Actually, they do:

a_list += an_item

and find it does not do what they want, and then the get confused, and I
show that they need:

a_list += [an_item]

or

a_list.append(an_item)

(this gets particularly confusing them an_item is, itself, a sequence (a
string is really common).

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

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.

-CHB



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to