<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 2 March 2017 at 07:03, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On Wed, Mar 1, 2017 at 11:13 AM, Abe Dillon <span dir="ltr"><<a href="mailto:abedillon@gmail.com" target="_blank">abedillon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I'd like to +1 this proposal. It should be trivial to implement. It won't break backward compatibility. It's intuitive. I can think of several places I would use it. I can't think of a good reason not to include it.</div></blockquote><div><br></div></span><div>I've yet to see in this thread a use case where list.get() would make sense. Specifically, I've yet to see a case where there is straightforward duck-typing substitutability between dicts and lists where you'd want that.</div></div></div></div></blockquote><div><br></div><div>I've never wanted a `list.get`, but I have occassionally wished that:<br><br></div><div>1. operator.get/set/delitem were available as builtins (like get/set/delattr)<br></div><div>2. the builtin getitem accepted an optional "default" argument the way getattr does<br><br></div><div>That is, the desired common operation isn't specifically "obj.get(subscript)" or "obj.get(subscript, default)", it's:<br><br></div><div> _raise = object()<br></div><div> def getitem(container, subscript, default=_raise):<br></div><div> try:<br></div><div> return container[subscript]<br></div><div> except LookupError:<br></div><div> if default is _raise:<br> raise<br></div><div> return default<br><br></div><div>Mappings just happen to already offer that functionality as a method.<br></div><br></div><div class="gmail_quote">Cheers,<br></div><div class="gmail_quote">Nick.<br></div><br>-- <br><div class="gmail_signature">Nick Coghlan | <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> | Brisbane, Australia</div>
</div></div>