On 27.08.2020 17:53, David Mertz wrote: > 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.
Really ? Let me try again :-) Getting an item from a bag of unknown items can easily fail, because you don't what's in the bag until you try to find the item. Trying to access an item from a non-existing bucket in an array will always fail. You know that in advance, since the bucket doesn't exist as per the array properties. You don't have to try finding it first. Not sure whether I'm getting the difference across. Grabbing into the void is different than grabbing into the dark :-) You might actually find something in the dark. > 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 :-). Well, I did a long time ago and hardly ever used it. For me, both are signs of "looks useful on the outside, but isn't in reality". -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Aug 27 2020) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ _______________________________________________ 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/44B3KCAJZMZ53HPENTFH76EJIYQSPIMV/ Code of Conduct: http://python.org/psf/codeofconduct/