[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Steven D'Aprano
On Tue, Jun 29, 2021 at 01:37:59AM +0100, Rob Cliffe via Python-ideas wrote: >     for i in range(0, 10): if i not in range(2, 8): >         > # This is arguably slightly easier to read than having two separate > lines, "Arguably" is an understatement. > as it puts both aspects of a single con

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Chris Angelico
On Tue, Jun 29, 2021 at 5:04 PM Steven D'Aprano wrote: > > On Tue, Jun 29, 2021 at 01:37:59AM +0100, Rob Cliffe via Python-ideas wrote: > > > for i in range(0, 10): if i not in range(2, 8): > > > > # This is arguably slightly easier to read than having two separate > > lines, > > "Arg

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Henk-Jaap Wagenaar
I think the more realistic option is to allow "if" in the for statement. This has been suggested before, you can find it in the archives. On Mon, 28 Jun 2021, 22:50 Max Shouman, wrote: > This is more of a syntactic sugar than an actual new feature, but... > Exactly, 'but' is the idea: a special

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Steven D'Aprano
On Tue, Jun 29, 2021 at 05:17:36PM +1000, Chris Angelico wrote: > What if you loop over the values in the range(0, 10) but skip all of > the odd numbers? Is that two concepts too? Of course it is. Think about somebody who knows about looping, and knows what range() does, but has no concept of od

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Chris Angelico
On Tue, Jun 29, 2021 at 7:15 PM Steven D'Aprano wrote: > > On Tue, Jun 29, 2021 at 05:17:36PM +1000, Chris Angelico wrote: > > > What if you loop over the values in the range(0, 10) but skip all of > > the odd numbers? Is that two concepts too? > > Of course it is. Think about somebody who knows a

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Steven D'Aprano
On Tue, Jun 29, 2021 at 07:27:11PM +1000, Chris Angelico wrote: > My point is that the *iteration* isn't any different - the *range* is > what's different. A filtered range makes very good sense here. Hence, > a disjoint range object (one capable of subtraction) would be an > excellent solution to

[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-29 Thread Chris Angelico
On Tue, Jun 29, 2021 at 8:29 PM Steven D'Aprano wrote: > > On Tue, Jun 29, 2021 at 07:27:11PM +1000, Chris Angelico wrote: > > > My point is that the *iteration* isn't any different - the *range* is > > what's different. A filtered range makes very good sense here. Hence, > > a disjoint range obje