<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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 class=""><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><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><br clear="all"><div><br></div>-- <br><div class="gmail_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>
</div></div>