Re: RFC: For Loop Invariants

2020-04-20 Thread Vincent Vande Vyvre
Le 20/04/20 à 13:08, Tony Flury via Python-list a écrit : > > On 10/04/2020 21:44, Elliott Dehnbostel wrote: >> *We could do this:* >> >> chars = "abcaaabkjzhbjacvb" >> seek = {'a','b','c'} >> count = sum([1 for a in chars if a in seek]) >> >> However, this changes important semantics by creating a

Re: RFC: For Loop Invariants

2020-04-20 Thread Tony Flury via Python-list
On 10/04/2020 21:44, Elliott Dehnbostel wrote: *We could do this:* chars = "abcaaabkjzhbjacvb" seek = {'a','b','c'} count = sum([1 for a in chars if a in seek]) However, this changes important semantics by creating an entire new list before summing. Creating the list is pointless in this ca

Re: RFC: For Loop Invariants

2020-04-11 Thread Peter J. Holzer
On 2020-04-10 15:44:05 -0500, Elliott Dehnbostel wrote: > *Consider the following trivial for-loop:* > > chars = "abcaaabkjzhbjacvb" > seek = {'a','b','c'} > count = 0 > for a in chars: > if a in seek: > count += 1 > > Gross. Twice nested for a simple count. > [...] > I propose th

Re: RFC: For Loop Invariants

2020-04-11 Thread Terry Reedy
On 4/10/2020 4:44 PM, Elliott Dehnbostel wrote: chars = "abcaaabkjzhbjacvb" seek = {'a','b','c'} count = 0for a in chars: if a in seek: count += 1 Why did you repeatly omit the \n after 0? Please paste code that ran Gross. Twice nested for a simple count. Twice indented d

Re: RFC: For Loop Invariants

2020-04-11 Thread Rhodri James
On 10/04/2020 21:44, Elliott Dehnbostel wrote: Hello Everyone, I've also posted this to the python-ideas mailing list, but I thought to post here as well for a more general audience. If I've done this incorrectly, please let me know so that I can improve/revise. I'm new to the Python community

Re: RFC: For Loop Invariants

2020-04-10 Thread Souvik Dutta
Ah yes it's an iterable not a condition. Sorry about that. 😛😛 Souvik flutter dev On Sat, Apr 11, 2020, 6:38 AM Chris Angelico wrote: > On Sat, Apr 11, 2020 at 11:04 AM Souvik Dutta > wrote: > > > > How about completely removing the need for an if statement by allowing > for multiple conditions

Re: RFC: For Loop Invariants

2020-04-10 Thread Chris Angelico
On Sat, Apr 11, 2020 at 11:04 AM Souvik Dutta wrote: > > How about completely removing the need for an if statement by allowing for > multiple conditions to be inserted in the for loop?? That would make reading > and writing a lot easier. Like the count problem could be rewritten as > for (a in

Re: RFC: For Loop Invariants

2020-04-10 Thread Souvik Dutta
How about completely removing the need for an if statement by allowing for multiple conditions to be inserted in the for loop?? That would make reading and writing a lot easier. Like the count problem could be rewritten as for (a in chars and ): count+=1 On Sat, 11 Apr, 2020, 6:21 am Chris An

Re: RFC: For Loop Invariants

2020-04-10 Thread Chris Angelico
On Sat, Apr 11, 2020 at 10:32 AM Juergen Brendel wrote: > > > Hello! > > On Fri, 2020-04-10 at 15:44 -0500, Elliott Dehnbostel wrote: > > chars = "abcaaabkjzhbjacvb" > > seek = {'a','b','c'} > > count = 0 > > > > for a in chars if a in seek: count += 1 > > Interesting proposal. However, I'm not su

Re: RFC: For Loop Invariants

2020-04-10 Thread Juergen Brendel
Hello! On Fri, 2020-04-10 at 15:44 -0500, Elliott Dehnbostel wrote: > chars = "abcaaabkjzhbjacvb" > seek = {'a','b','c'} > count = 0 > > for a in chars if a in seek: count += 1 Interesting proposal. However, I'm not sure how much benefit it really will give us in practice. Reason being: Conditi

Re: RFC: For Loop Invariants

2020-04-10 Thread DL Neil via Python-list
On 11/04/20 8:44 AM, Elliott Dehnbostel wrote: If I've done this incorrectly, please let me know so that I can improve/revise. I'm new to the Python community and quite enjoy the more functional features of Python 3, but have I have a peeve about it. I'd like to propose and discuss the following

RFC: For Loop Invariants

2020-04-10 Thread Elliott Dehnbostel
Hello Everyone, I've also posted this to the python-ideas mailing list, but I thought to post here as well for a more general audience. If I've done this incorrectly, please let me know so that I can improve/revise. I'm new to the Python community and quite enjoy the more functional features of P