[Python-ideas] List get/pop

2023-06-14 Thread Dom Grigonis
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

[Python-ideas] Re: List get/pop

2023-06-14 Thread Chris Angelico
On Thu, 15 Jun 2023 at 06:04, Dom Grigonis 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 generou

[Python-ideas] Re: List get/pop

2023-06-14 Thread Dom Grigonis
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