I'm a lurker on this list and wanted to submit my own idea. It's a feature
I've been wanting in Python for a while, and I have a simple implementation
for it for personal use at the moment. Wanted to get feedback before I move
forward.
Essentially, I want to be able to perform a simple default get on a list if
an index does not exist, similar to a dictionary. For example:
*my_dict = {"test1": "value1"}*
*my_dict.get("test2", None)*
results in a "None" value, since the key doesn't exist.
Similarly with a list:
*my_list = [1, 2, 3]*
*my_list.get(10, 0)*
says that since index 10 does not exist, I expect a 0 to be returned.
Currently, you have to check the length of the list of use a try/except,
which takes more lines than I'd like to use.
I'm welcoming feedback on this feature, or if it's already been discussed
then I'm expecting to be shut down.
Thank you for your time!