[Python-ideas] IndexableDict? [was: dict_items.__getitem__?]

2021-10-11 Thread Stephen J. Turnbull
Alex Waygood writes: > > Should `dict.items()` be indexable now that dicts are ordered? I > > say yes. Why shouldn't it? Read on, MacDuff! > Would there be a way to ensure that this had the same time > complexity as indexing of sequences? Depends on what you mean by "same". I wrote the fol

[Python-ideas] Re: Adding a Version type

2021-10-11 Thread Rob Cliffe via Python-ideas
On 10/10/2021 13:31, Steven D'Aprano wrote: On Sat, Oct 09, 2021 at 08:16:58PM -0600, Finn Mason wrote: import sys if sys.version_info < (3, 6): # Yell at the user Please, version checking is usually an anti-pattern! You should use feature detection whenever possible, not version checki

[Python-ideas] Re: Adding a Version type

2021-10-11 Thread Chris Angelico
On Mon, Oct 11, 2021 at 10:59 PM Rob Cliffe via Python-ideas wrote: > > > > On 10/10/2021 13:31, Steven D'Aprano wrote: > > On Sat, Oct 09, 2021 at 08:16:58PM -0600, Finn Mason wrote: > > > >> import sys > >> if sys.version_info < (3, 6): > >> # Yell at the user > > Please, version checking i

[Python-ideas] Re: Adding a Version type

2021-10-11 Thread Paul Moore
On Mon, 11 Oct 2021 at 13:05, Chris Angelico wrote: > In any case, there's not a lot of need to support Python 2 any more, > so most of this sort of check doesn't exist in my code any more. ... and in particular, "useful to help with code that needs to support Python 2" won't work as an argument

[Python-ideas] Re: dict_items.__getitem__?

2021-10-11 Thread Erik Demaine
There seems to be a growing list of issues with adding `itertools.first(x)` as shorthand for `next(iter(x))`: * If `x` is an iterator, it modifies the iterator, which is counterintuitive from the name `first`. * It'll still be difficult for new users to find/figure out. In the end, I feel li

[Python-ideas] Re: dict_items.__getitem__?

2021-10-11 Thread Steven D'Aprano
On Mon, Oct 11, 2021 at 06:59:14PM -0400, Erik Demaine wrote: > In the end, I feel like the main case I want to use a `first` and `last` > functions on are `dict`s; "I want to use first on dicts" is not really a use-case. Presumably you're not just doing: d = {key: value, ...} who_care

[Python-ideas] Re: dict_items.__getitem__?

2021-10-11 Thread Christopher Barker
Please do go back and read that previous thread, there was a LOT of discussion and much detail. "I want to use first on dicts" is not really a use-case. quite true -- what IS the use case(s) here? But honestly, I'm even more confused by the desire for the last item -- what's the use case for tha