<div dir="ltr">I wouldn't see myself using it for an arbitrary value in the middle of the list, but perhaps for the 0th or -1st (first/last) element of a list that might be empty. Maybe also second-to-first/last if I'm initializing some comparison between sequential items?<div><br></div><div>Some of the examples don't work with negative indexes, boo.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 12:52 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</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 class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Feb 28, 2017 at 10:10 AM, Sven R. Kunze <span dir="ltr"><<a href="mailto:srkunze@mail.de" target="_blank">srkunze@mail.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Yes, and easily written as above. What significant
advantage would it have to spell the above as:</div>
<div><br>
</div>
<div> x = alist.get(pos, default_val)</div>
<div><br>
</div>
<div>It's a couple characters shorter in the proposed
version. I guess I'll concede that needing the odd
indexing at the end to get the scalar is slightly ugly.</div></div></div></div></blockquote></span>
1. advantage: it looks like dict access -> allows duck typing (oh
how often I'd missed that)<br>
2. advantage: no try except<br>
3. advantage: no weird workaround with slices and additional item
access<br></div></blockquote><div><br></div></span><div>How often would you duck-type "access either an integer position or a named key in a collection?"</div><div><br></div><div>I'm all for duck typing, but it feels like those are a pretty different pattern. For example, I know that if a list has something at index 10 it also has something at index 9. I absolutely *do not* know that if a dict has something at key 'g' it also has something at key 'f'.</div></div><span class=""><br clear="all"><div><br></div>-- <br><div class="m_4835261617901075309gmail_signature" data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</span></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div><br></div>