[Python-ideas] Re: dict_items.__getitem__?

2021-10-05 Thread Alex Waygood
I think there definitely should be a more obvious way to do this (specifically the first and last keys/values/items of a dictionary — I'm ambivalent about the others, since they won't always be fast, as discussed). An anti-pattern you see quite often on Stack Overflow to get the first key of a

[Python-ideas] Re: More efficient list copying

2021-10-05 Thread Gregory P. Smith
On Sat, Oct 2, 2021, 10:20 PM Christopher Barker wrote: > > But sure, if we can eliminate inefficiencies in Python standard data > types, then why not? > Because the C implementation becomes hard to maintain. All of our linear containers could benefit from non-linear implementations in some sce

[Python-ideas] Re: dict_items.__getitem__?

2021-10-05 Thread Christopher Barker
> >- dict.first_key = lambda self: next(iter(self)) >- dict.first_val = lambda self: next(iter(self.values())) >- dict.first_item = lambda self: next(iter(self.items())) >- dict.last_key = lambda self: next(reversed(self)) >- dict.last_val = lambda self: next(reversed(self.value

[Python-ideas] Re: dict_items.__getitem__?

2021-10-05 Thread Alexander Hill
> Except many iterables don’t have a last item. And many more can’t give you the last item efficiently. That's manageable - reversed won't work either unless the object either implements either __reversed__, or __len__ and __getitem__. last could simply fail under the same conditions, in which cas