[Python-ideas] get() method for list and tuples

Michel Desmoulin desmoulinmichel at gmail.com
Tue Feb 28 20:18:47 EST 2017


I love this proposal but Guido rejected it. Fighting for it right now
would probably be detrimental to the current proposed feature which
could potentially be more easily accepted.

At least let's make it a separate thread. I would love to restart the
debate about this one. This is one of my most wanted feature ever in Python.

Le 01/03/2017 à 01:22, Rob Cliffe a écrit :
> 
> 
> 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
> Rob Cliffe
>>
>> Also, for list, a list.setdefault like the dict.setdefault would be
>> logical.
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list