On Thu, Aug 27, 2020 at 11:37 AM M.-A. Lemburg <m...@egenix.com> wrote:

> Asking a dict d of potentially any number of items for
> existence of a particular item x is somewhat different than asking
> a list l of a certain length i for the item at position i+1.
>

Suppose we didn't have dict.get().  I would then probably write:

    val = mydict[key] if key in mydict else None

Likewise, since we don't have list.get(), I would write:

    val = mylist[N] if len(mylist) >- N-1 else None

Neither of those is impractical, but in both cases .get(key) seems to
express the intent in a more obvious way.

That said, it is trivial to write a get() function that does the same
thing... and I've never bothered to do so.  In fact, I could write a get()
function that was polymorphic among mappings and sequences with very little
work, which I've also never done.  So I guess my case for the huge
importance is undercut :-).

-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HB65FPUS3JX34457FYTJ4U7ZAQUWGF3O/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to