[Python-ideas] Re: dict_items.__getitem__?

2021-10-04 Thread Christopher Barker
On Mon, Oct 4, 2021 at 5:46 PM Erik Demaine wrote: > Have folks thought about allowing indexing dictionary views as in the > following code, where d is a dict object? > > d.keys()[0] > d.keys()[-1] > d.values()[0] > d.values()[-1] > d.items()[0] > d.items()[-1] # item that would be returned by

[Python-ideas] Re: dict_items.__getitem__?

2021-10-04 Thread Inada Naoki
On Tue, Oct 5, 2021 at 9:46 AM Erik Demaine wrote: > Of course, the universal way to get the > first item from an iterable x is > > item = next(iter(x)) > > I can't say this is particularly readable, but it is functional and fast. I think we can add `itertools.first()` for this idiom, and

[Python-ideas] dict_items.__getitem__?

2021-10-04 Thread Erik Demaine
Have folks thought about allowing indexing dictionary views as in the following code, where d is a dict object? d.keys()[0] d.keys()[-1] d.values()[0] d.values()[-1] d.items()[0] d.items()[-1] # item that would be returned by d.popitem() I could see value to the last form in particular: you

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Chris Angelico
On Tue, Oct 5, 2021 at 9:50 AM Caleb Donovick wrote: > > > 2) Some OTHER exception occurs on the reevaluation. It's a chained > > exception like any other. > > Except it's not a chained exception and displaying as such would be VERY > confusing IMO. > Granted we could easily strip the chained

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Caleb Donovick
> 2) Some OTHER exception occurs on the reevaluation. It's a chained > exception like any other. Except it's not a chained exception and displaying as such would be VERY confusing IMO. Granted we could easily strip the chained exception and just return the original one. So after reconsideration

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Caleb Donovick
> I wonder, could this be simplified a bit, on the assumption that a > well-written assertion shouldn't have a problem with being executed > twice? While I agree as an engineering principle an assert should not have side effects and hence re-evaluation should be fine in most cases, it is not

[Python-ideas] Re: Power Assertions: Is it PEP-able?

2021-10-04 Thread Chris Angelico
On Tue, Oct 5, 2021 at 9:02 AM Caleb Donovick wrote: > > > I wonder, could this be simplified a bit, on the assumption that a > > well-written assertion shouldn't have a problem with being executed > > twice? > > While I agree as an engineering principle an assert should not have side > effects

[Python-ideas] Re: Feature request enumerate_with_rest or enumerate with skip or filter callback

2021-10-04 Thread Laurent Lyaudet
Le dim. 3 oct. 2021 à 16:21, a écrit : > Date: Mon, 4 Oct 2021 01:03:34 +1100 > From: Steven D'Aprano > Subject: [Python-ideas] Re: Feature request enumerate_with_rest or > enumerate with skip or filter callback > To: python-ideas@python.org > Message-ID:

[Python-ideas] Re: Python-ideas Digest, Vol 179, Issue 25

2021-10-04 Thread Laurent Lyaudet
Le dim. 3 oct. 2021 à 16:21, a écrit : > Date: Mon, 4 Oct 2021 01:03:34 +1100 > From: Steven D'Aprano > Subject: [Python-ideas] Re: Feature request enumerate_with_rest or > enumerate with skip or filter callback > To: python-ideas@python.org > Message-ID:

[Python-ideas] Re: Syntax Sugar for __name__ == "__main__" boilerplate?

2021-10-04 Thread Abdur-Rahmaan Janhangeer
Greetings list, Just a funny Reddit quote: (.NET 5 minimal APIs are even easier, and I swear .NET starts to feel more like Python to me all the time, especially since they removed the need for a Main method).

[Python-ideas] Re: Shorthand syntax for lambda functions that have a single parameter

2021-10-04 Thread Dominik Vilsmeier
Abdulla Al Kathiri wrote: > Oh I forgot what if you want to return a set from your lambda? Maybe a lambda > set should at least have one assignment statement to qualify it as one. > Expressions only inside a set syntax will be just a normal set that doesn’t > care about order as you pointed