[Python-ideas] get() method for list and tuples
rob.cliffe at btinternet.com
Tue Feb 28 19:22:38 EST 2017
On 28/02/2017 11:54, Michel Desmoulin wrote:
> dict.get() is a very useful method, but for lists and tuples, we need to
> rely on try/except instead.
> Can we get list.get and tuple.get as well?
If PEP 463 "Exception-catching expressions" were accepted and
implemented, we wouldn't need any of them:
val = myDict[k] except KeyError: default
val = myList[n] except IndexError: default
> Also, for list, a list.setdefault like the dict.setdefault would be logical.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas