
Very simple proposal. E.g. ```
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!

On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
That was me being VERY generous to the other proposal :) At very best, what you're seeing is an *upper bound* on the number of people referenced, but I wasn't actually arguing numbers there so much as disputing the incredulity given. HOWEVER: Your proposal is much easier to make backward compatible. Adding a keyword-only parameter to a method that currently doesn't accept keyword arguments is (a) not going to conflict with current code, and (b) will instantly error out if someone attempts to use this feature on a Python that doesn't support it, so it's not going to cause subtle errors. Though, notably, this would count as another use-case for PEP 463, if anyone felt like reviving that. ChrisA

On Fri, Jun 16, 2023 at 4:20 AM Dom Grigonis <dom.grigonis@gmail.com> wrote:
Just to add. I think same methods would be useful to have for strings as well.
strings are immutable, so `pop` is out. As for `get` -- it *could* be added to the sequence ABC, but very much doubt that will ever happen -- adding something to an ABC is very heavy lift. -CHB
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython

On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
That was me being VERY generous to the other proposal :) At very best, what you're seeing is an *upper bound* on the number of people referenced, but I wasn't actually arguing numbers there so much as disputing the incredulity given. HOWEVER: Your proposal is much easier to make backward compatible. Adding a keyword-only parameter to a method that currently doesn't accept keyword arguments is (a) not going to conflict with current code, and (b) will instantly error out if someone attempts to use this feature on a Python that doesn't support it, so it's not going to cause subtle errors. Though, notably, this would count as another use-case for PEP 463, if anyone felt like reviving that. ChrisA

On Fri, Jun 16, 2023 at 4:20 AM Dom Grigonis <dom.grigonis@gmail.com> wrote:
Just to add. I think same methods would be useful to have for strings as well.
strings are immutable, so `pop` is out. As for `get` -- it *could* be added to the sequence ABC, but very much doubt that will ever happen -- adding something to an ABC is very heavy lift. -CHB
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
participants (3)
-
Chris Angelico
-
Christopher Barker
-
Dom Grigonis