This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: There should be a list.get just like dict.get
Type: enhancement Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Abram Clark, rhettinger
Priority: normal Keywords:

Created on 2018-11-16 01:44 by Abram Clark, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg329978 - (view) Author: Abram Clark (Abram Clark) Date: 2018-11-16 01:44
Just like with dictionaries, it is convenient to index lists without catching exceptions. Adding an import for this most basic functionality is slightly tedious, and I can't imagine it would break anything to add a list.get method.
msg329981 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-11-16 05:53
This idea has been discussed before and was rejected.  While get() makes sense and has valid use cases for dictionaries which use key based lookups, there isn't a parallel for lists.  In general, we do just fine without list.get().   Also, it seems that other languages have mostly made the same decision in this regard.

Thank you for the suggestion though.
msg329983 - (view) Author: Abram Clark (Abram Clark) Date: 2018-11-16 08:36
There really are valid use cases for this. Would you please refer me to this previous discussion? In a particular small to medium sized Python repository of ~10k lines, list get is used 23 times, whereas other list builtin methods are used far less (for example list.pop is used once, though dict.pop is used 18 times). I would be happy to go into specific examples.
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79443
2018-11-16 08:36:01Abram Clarksetmessages: + msg329983
2018-11-16 05:53:42rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg329981

resolution: rejected
stage: resolved
2018-11-16 01:44:22Abram Clarkcreate