New submission from Felix <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue32979>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com