Very simple proposal.

E.g.
```
>>> l = [‘a’, ‘b’]
>>> l.get(0)
‘a’
>>> l.get(2)
None
>>> l.pop(1, default=‘c’)
‘b’
>>> l.pop(1, default=‘c’)
‘c'
```

Essentially to match them to those of a dict.
Current workarounds:
```
try:
   a = b[n]
except IndexError:
   a = default

# and

l[index] if -len(l) <= index < len(l) else default
```

Benefits:
1. Convenience
2. Easy to remember API methods for anyone used to a dict
3. Speed improvements given it’s implemented in C
4. Time saving!
It took me around 7seconds to type 2nd snippet without auto-complete.

So following Chris’ logic...
If there are 10,000,000 python users on Stack…
And we assume, that every user encounters such need at least 2 times a year 
(being very speculative here, would say conservative?).
Saving on typing and correcting above snippet is 5sec (conservative here?).
That’s ~600 days of pure code writing time saved every year.
In 100 years, which python will obviously survive - that’s ~16.5 years of pure 
code typing time saved worldwide!








_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KYSFT4NKIRZNQ6H46VZ6BYUNWIJZ2OEP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to