<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p><span>>I think the first place to start would be to either set a default argument for "insert"</span></p>
<p><span>>or add an optional argument for "append", but in both cases that would again be</span></p>
<p><span>>duplicating functionality so I don't see the point.</span></p>
<p><span>- Todd<br>
</span></p>
<p><br>
</p>
<p>That would be fine too; the main idea is just having a method that's symmetrically related to pop(). append(2, 2) would seem awkward, but it could work with insert(2).</p>
<p><br>
</p>
<p></p>
<div>><font size="2"><span style="font-size:10pt">However, for most people, "append an item to a list", "insert an item<br>
>into a list" and "extend a list" are common English phrases, while<br>
>"push an item onto a list" would get you funny looks,<br>
</span></font></div>
<p>-Nick Coghlan<br>
</p>
<p></p>
<p><br>
</p>
<p>This is an interesting argument, because English isn't my first language, so it's not something I would think of. Having a programming language obey the laws of spoken English seems uncalled for, but it's still a good point. The name could be something more
 natural, of course. (Even so, is "pop() an item from a list" any better?)</p>
<p><br>
</p>
<p>><span>There is absolutely zero chance that append and insert are going away. That would break everything.</span></p>
<p>- Todd</p>
<p>><font size="2"><span style="font-size:10pt">There's zero chance of the existing APIs going away
</span></font></p>
<p>- Nick Coghlan<br>
</p>
<br>
<p>It was hypothetical, but you're probably right.</p>
<p><br>
</p>
<p>><font size="2"><span style="font-size:10pt">I don't think it makes sense to add the method</span></font></p>
<p>- Nick Coghlan<br>
</p>
<p><br>
</p>
<p>It makes sense to have inverse methods. pop() pops off the last item and pop(i) pops off the ith item. There are no methods such that push(obj) pushes the item onto the end and push(obj, index) pushes the item onto the ith position. That would be append(obj)
 and insert(obj, index), but there's no symmetric relation here. This is harder to learn, so it would be better to have a unified method for the inverse. Todd's suggestion of letting the index parameter for insert() be optional would accomplish the same result,
 without having to add an additional method.</p>
<p><br>
</p>
<p>~Paul<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Nick Coghlan <ncoghlan@gmail.com><br>
<b>Sent:</b> Monday, May 22, 2017 7:47:42 AM<br>
<b>To:</b> Paul Laos<br>
<b>Cc:</b> python-ideas@python.org<br>
<b>Subject:</b> Re: [Python-ideas] Suggestion: push() method for lists</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On 22 May 2017 at 00:43, Paul Laos <paul_laos@outlook.com> wrote:<br>
> So while it has been discussed before, it's worth bringing up again, since<br>
> this was before the release of Python 2.0.<br>
<br>
It was also before the addition of collections.deque. which uses<br>
appendleft() and extendleft(), rather than pushleft().<br>
<br>
> Pros:<br>
><br>
> - Would simplify the language by having a symmetric relation to pop().<br>
> - Would make it easy to use lists as stacks.<br>
<br>
I think the key argument here would be that *for folks that already<br>
know the push/pop terminology for stack data structures*, "push" is a<br>
potentially more intuitive term than the insert/append/extend trio.<br>
<br>
However, for most people, "append an item to a list", "insert an item<br>
into a list" and "extend a list" are common English phrases, while<br>
"push an item onto a list" would get you funny looks, and even "push<br>
an item onto a stack" would be unusual in a spoken conversation (the<br>
non-jargon phrase in that case is "add an item to the stack", but<br>
"add" would be ambiguous between the append() and extend() meanings)<br>
<br>
As a result, the specific-to-computer-science jargon loses out.<br>
<br>
The situation for `pop()` is different, as `remove()` is already taken<br>
for "remove an item from the list by value", so a different word is<br>
needed for "remove an item from the list by index".<br>
<br>
> - If append()/insert() are being removed and replaced, the complexity of<br>
> lists is slightly reduced.<br>
<br>
There's zero chance of the existing APIs going away - they're not<br>
broken, and they match common English phrasing. The fact they don't<br>
match common computer science jargon isn't ideal, but it's<br>
relevatively straightforward to define a stack data structure if<br>
someone really wants to do so.<br>
<br>
> Cons:<br>
><br>
> - Would blur the line between lists and stacks.<br>
><br>
> - The order of the parameters in push(obj, index = -1) would be the opposite<br>
> of the parameters in insert(index, obj), because defaulted parameters come<br>
> last.<br>
<br>
While I don't think it makes sense to add the method in the first<br>
place, if we did, it either wouldn't accept an index parameter, or<br>
else the index parameter would be a keyword-only argument.<br>
<br>
Cheers,<br>
Nick.<br>
<br>
-- <br>
Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia<br>
</div>
</span></font>
</body>
</html>