<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Jun 18, 2018 at 12:56 PM Mikhail V <<a href="mailto:mikhailwas@gmail.com">mikhailwas@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Numpy arrays have also append() and insert() methods,<br></blockquote><div><br></div><div><div>In [2]: np.arange(1).append(2)</div><div>AttributeError: 'numpy.ndarray' object has no attribute 'append'<br></div></div><div><br></div><div>In [3]: np.arange(1).insert<br></div><div><div>AttributeError: 'numpy.ndarray' object has no attribute 'insert'</div></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">So one syntax generalization possible is towards insert() method.<br></blockquote><div><br></div><div>Why would you even want to encourage inserting into a list? It's slow and should be *discouraged*.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Although IMO it could be made into nice syntax only by introducing<br>some symbol into the index notation. For example:<br><br>L[] = item append(item)<br>L[^] = item ? appendleft(item)<br>L[^0] = item insert (0, item)<br>...<br>L[^i] = item insert(i, x)<br><br>Note, I am not responsible for the adequacy of the technical<br>part - since it may be not plausible technically.<br></blockquote><div><br></div><div>Indeed, changing the syntax to add a special meaning to caret operator inside of index assignment is a *major* change. Not worthwhile for such dubious benefit.</div><div><br></div></div></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">On Mon, Jun 18, 2018 at 1:08 PM Joao S. O. Bueno <<a href="mailto:jsbueno@python.org.br">jsbueno@python.org.br</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">MutableSequence protocol to define "<<" as "append"</blockquote><div><br></div><div>No one has demonstrated with any realistic examples why code would look better with ``a <<= b`` instead of ``a.append(b)``. Perhaps a language in its infancy could toy with new spellings, but Python is old now and should be more cautious with change.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I know that at least Brython used the "<<=" enhanced assignement<br>
operator to manipulate HTML DOM, and it often results in<br>
quite compact code when compared with javascript-equivalente manipulations.<br></blockquote><div><br></div><div>That sounds great for a dedicated HTML DOM manipulation tool, but not for the core list type.</div><div><br></div><div><br></div><div><br></div><div><div class="gmail_quote"><div dir="ltr">On Sun, Jun 17, 2018 at 6:12 PM Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>> wrote:<br></div></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Actually, maybe the problem here is that there's no easy way to<br>represent "-0" in a slice.<br>>>> items[:0] = ["shim"] # insert at beginning<br></blockquote></div></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">>>> items[-0:] # failed parallel<br></blockquote><div><br></div><div><div>The fact that signed 2's complement integers don't support negative zero does cause some problems for both indexing and slicing. However, to me it seems this is a fundamental human problem with zero. Thus the ever-present off-by-one error. I can't think of a solution that doesn't cause more harm than good.</div></div></div></div></div></div></div>