<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 21, 2017 at 10:43 AM, Paul Laos <span dir="ltr"><<a href="mailto:paul_laos@outlook.com" target="_blank">paul_laos@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div id="m_8442751001633612155divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" dir="ltr">
<p></p>
<div style="color:rgb(0,0,0)">
<div id="m_8442751001633612155divRplyFwdMsg" dir="ltr">It would be nice to have the opposite of the pop() method: a push() method. While insert() and append() already exist, neither is the opposite of pop(). pop() has a default index parameter -1, but neither insert() nor append() has
 a default index parameter. push(obj) would be equivalent to insert(index = -1, object), having -1 as the default index parameter. In fact, push() could replace both append() and insert() by unifying them.
</div>
<div>
<br><div id="m_8442751001633612155divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif">
<p><br>
</p>
<p>By default push(obj) would insert an object to the end of the list, while push(obj, index) would insert the object at index, just like pop() removes (and returns) the object at the end of the list, and pop(index) removes (and returns) the object at the index.</p>

<p><br>
I found little discussion on this, just this SO thread <a href="http://stackoverflow.com/questions/1566266/why-is-pythons-append-not-push" class="m_8442751001633612155OWAAutoLink" id="m_8442751001633612155LPlnk101796" target="_blank">
http://stackoverflow.com/<wbr>questions/1566266/why-is-<wbr>pythons-append-not-push</a> which lead to a discussion from 20 years ago (1997):
<a href="https://groups.google.com/forum/#!topic/comp.lang.python/SKJq3S2ZYm" class="m_8442751001633612155OWAAutoLink" id="m_8442751001633612155LPlnk617443" target="_blank">
</a><a href="https://groups.google.com/forum/#!topic/comp.lang.python/SKJq3S2ZYmg" class="m_8442751001633612155OWAAutoLink" id="m_8442751001633612155LPlnk940405" target="_blank">https://groups.google.com/<wbr>forum/#!topic/comp.lang.<wbr>python/SKJq3S2ZYmg</a>
<a href="https://groups.google.com/forum/#!topic/comp.lang.python/SKJq3S2ZYmg" class="m_8442751001633612155OWAAutoLink" id="m_8442751001633612155LPlnk959222" target="_blank">
</a><br>
</p>
<p><br>
</p>
<p>Some key arguments from the thread:</p>
<p><br>
</p>
<div>>it would be an <br>
>easy and obvious improvement to make popend an explicit builtin, and <br>
>that this would make Python even more attractive to newcomers who want <br>
>to use what they already know and be immediately productive.<br>
<div>
<div>- <span class="m_8442751001633612155_username"><span class="m_8442751001633612155IVILX2C-D-a" style="color:rgb(34,34,34)">Terry Reedy</span></span></div>
</div>
</div>


<p><span class="m_8442751001633612155_username"><span class="m_8442751001633612155IVILX2C-D-a" style="color:rgb(34,34,34)"></span></span><br>
</p>
<div>>append() is a special case of insert().  The inverse of insert() is<br>
>the del function.  The specific inverse of append() is del list[-1].<br>
<div>- <span class="m_8442751001633612155_username"><span class="m_8442751001633612155IVILX2C-D-a" style="color:rgb(34,34,34)">Michael W. Ryan</span></span></div>
</div>
<br>
<div>>but I'm not a big fan of multiple names for the same operation --<br>
>sooner or later you're going to read code that uses the other one, so<br>
>you need to learn both, which is more cognitive load.<br>
<span class="m_8442751001633612155_username"><span class="m_8442751001633612155IVILX2C-D-a" style="color:rgb(34,34,34)">- Guido van Rossum</span></span><br>
</div>

<p><br>
</p>
<p>So while it has been discussed before, it's worth bringing up again, since this was before the release of Python 2.0.<br>
</p>
<br>
<p>Pros:</p>
<p>- Would simplify the language by having a symmetric relation to pop().</p>
<p>- Would make it easy to use lists as stacks.</p>
<p>- Saves at least two characters</p>
<p>- If append()/insert() are being removed and replaced, the complexity of lists is slightly reduced.</p>
<p><br>
Cons:</p>
<p>- Would blur the line between lists and stacks.</p>
<p>- The order of the parameters in push(obj, index = -1) would be the opposite of the parameters in insert(index, obj), because defaulted parameters come last.</p>
<p>- If append()/insert() are being removed and replaced, backwards compatability breaks.</p>
<p>- If append()/insert() are kept instead of being replaced, the complexity of lists is slightly increased.</p>

<p><br>
</p>
<p>While it isn't a necessity, I believe the benefit of push() method outweighs its cons.<span class="HOEnZb"><font color="#888888"><br>
</font></span></p></div></div></div></div></div></blockquote><div><br></div><div>There is absolutely zero chance that append and insert are going away. That would break everything.<br><br></div><div>So with your proposal, we would end up with two methods that do exactly the same thing, differing only in the defaults and the order of arguments. That definitely does not make the language simpler.<br><br></div><div>The big question you need to ask when proposing a new feature for python is "what is the use-case for this?" What does this do that existing features can't do, or that existing features are significantly worse at? Since this literally duplicates the functionality of existing features, it doesn't have such a use-case<br><br></div><div>If we were changing things at all, I think the first place to start would be to either set a default argument for "insert" or add an optional argument for "append", but in both cases that would again be duplicating functionality so I don't see the point.<br></div></div></div></div>