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!
On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
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?).
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
Yes, 1. adding keyword argument for `pop` 2. implementing `get` method as it doesn’t exist at all * This wouldn’t break anything for sure. Well… theoretically could, but I find it hard to imagine anyone has written such code. I like PEP 463. Looks simple and intuitive.
On 14 Jun 2023, at 23:11, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
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?).
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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/2S6ZFA... Code of Conduct: http://python.org/psf/codeofconduct/
Just to add. I think same methods would be useful to have for strings as well.
On 14 Jun 2023, at 23:28, Dom Grigonis <dom.grigonis@gmail.com> wrote:
Yes, 1. adding keyword argument for `pop` 2. implementing `get` method as it doesn’t exist at all * This wouldn’t break anything for sure. Well… theoretically could, but I find it hard to imagine anyone has written such code.
I like PEP 463. Looks simple and intuitive.
On 14 Jun 2023, at 23:11, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
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?).
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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/2S6ZFA... Code of Conduct: http://python.org/psf/codeofconduct/
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
On 14 Jun 2023, at 23:28, Dom Grigonis <dom.grigonis@gmail.com> wrote:
Yes, 1. adding keyword argument for `pop` 2. implementing `get` method as it doesn’t exist at all * This wouldn’t break anything for sure. Well… theoretically could, but I find it hard to imagine anyone has written such code.
I like PEP 463. Looks simple and intuitive.
On 14 Jun 2023, at 23:11, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, 15 Jun 2023 at 06:04, Dom Grigonis <dom.grigonis@gmail.com> wrote:
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?).
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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/2S6ZFA... Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/ITFYOC... Code of Conduct: http://python.org/psf/codeofconduct/
-- 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