[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Stephen J. Turnbull
Alex Waygood writes: > the suggestion was to add two functions to itertools (first() and > last(), which would work with any iterable, OK, that wasn't obvious to me either, but good enough. I see the analogy to str's startswith and endswith, but I'm still -0 on these. The names suggest indexi

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread 2QdxY4RzWzUUiLuE
On 2021-10-06 at 08:52:22 -0600, Finn Mason wrote: > I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many > people use that feature. I honestly still think of them as unordered > ;) +1 on still think of mappings as unordered (but finding myself screaming Get Off My Lawn more an

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Eric V. Smith
> On Oct 6, 2021, at 10:53 AM, Finn Mason wrote: > >  > I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many people > use that feature. I honestly still think of them as unordered ;) > There’s tons of code that relies on dicts being ordered. Some just don’t know it. For exa

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Steven D'Aprano
On Wed, Oct 06, 2021 at 11:17:07AM -0400, Eric V. Smith wrote: > I think we can rely on dicts being ordered as a language guarantee for > the rest of time. Indeed. That's official and documented. "Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was a

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Finn Mason
On Wed, Oct 6, 2021, 9:23 AM Ricky Teachey wrote: > On Wed, Oct 6, 2021 at 10:55 AM Finn Mason wrote: > >> I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many >> people use that feature. I honestly still think of them as unordered ;) >> > > I've seen several people say this so

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Ricky Teachey
On Wed, Oct 6, 2021 at 10:55 AM Finn Mason wrote: > I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many > people use that feature. I honestly still think of them as unordered ;) > I've seen several people say this so I'll be a voice on the other side: I am not a pro developer

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Finn Mason
I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many people use that feature. I honestly still think of them as unordered ;) Let's talk code clarity. After all, to quote GvR, "Code is more often read than written." (I may have gotten the wording wrong, I just wrote it off the to

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Paul Bryan
+1. These would be handy for any iterable. It'll works on dict keys and values; bonus. On Wed, 2021-10-06 at 15:42 +0100, Alex Waygood wrote: > > Whether they are added to dict or itertools, there are still nine > > of  > > them > > No, the suggestion was to add two functions to itertools (first(

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Alex Waygood
> Whether they are added to dict or itertools, there are still nine of > them No, the suggestion was to add two functions to itertools (first() and last(), which would work with any iterable, not just dicts), rather than adding nine methods to the dict interface. This was precisely why I was sa

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Steven D'Aprano
On Wed, Oct 06, 2021 at 11:11:09AM +0100, Alex Waygood wrote: > > The temptation to insist "see, YAGNI!" at this point I shall resist. > > *You* might not need it, but I've seen it come up a lot on Stack > Overflow, and all too often people end up going for the much less > efficient solution. I

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Steven D'Aprano
On Tue, Oct 05, 2021 at 08:45:55AM +0100, Alex Waygood wrote: > I think there definitely should be a more obvious way to do this > (specifically the first and last keys/values/items of a dictionary What's your use-case for caring what the first and last key in a dict is? > An anti-pattern yo

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Alex Waygood
> The temptation to insist "see, YAGNI!" at this point I shall resist. *You* might not need it, but I've seen it come up a lot on Stack Overflow, and all too often people end up going for the much less efficient solution. I personally have also written code with practical applications using `ne

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Stephen J. Turnbull
Alex Waygood writes: > Whereas obviously, The temptation to insist "see, YAGNI!" at this point I shall resist. > a much better way (especially if it's a very large dictionary) is > to do: > > first_key = next(iter(mydict)) > [Inada Naoki] > > I think we can add `itertools.first(