[issue32979] dict get() function equivalent for lists.
Felix
report at bugs.python.org
Thu Mar 1 11:52:09 EST 2018
New submission from Felix <felix at meyerwolters.de>:
Hi there!
I hope this wasn't suggested before. I couldn't find any issues related to it.
The `get()` function on the dictionary object is such a convenient way for retrieving items from a dict that might not exists. I always wondered why the list object does not have an equivalent?
I constantly run into something like this:
myval = mylist[1] if len(mylist) > 1 else None
or worse like this:
try:
myval = mylist[1]
except IndexError:
myval = None
While I think it would be nice to do it like this:
myval = mylist.get(1)
Any love for this?
Cheers! :)
----------
messages: 313099
nosy: feluxe
priority: normal
severity: normal
status: open
title: dict get() function equivalent for lists.
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32979>
_______________________________________
More information about the Python-bugs-list
mailing list