Re: For loop comprehensions

2011-02-12 Thread Benjamin S Wolf
On Feb 11, 3:47 pm, Westley Martínez wrote: > No, too confusing. Then people'll want compound loops e.g.: > > for a in b if c while d else return x: >     print('Ha ha I'm so clever!') On Feb 11, 6:34 pm, Steven D'Aprano wrote: > There's nothing wrong with writing > > for x in iterable: >     if

Re: For loop comprehensions

2011-02-12 Thread Ian Kelly
On Fri, Feb 11, 2011 at 7:34 PM, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 16:59:52 -0700, Ian Kelly wrote: > >> Why not allow the same thing in for-loop conditions? > > Because new syntax and new language features means more work. Somebody > has to write the code, make sure that it doesn't bre

Re: For loop comprehensions

2011-02-11 Thread Terry Reedy
On 2/11/2011 6:10 PM, Benjamin S Wolf wrote: It occurred to me as I was writing a for loop that I would like to write it in generator comprehension syntax, eg. for a in b if c: Already proposed and rejected. See archives for python-ideas or the gmane.comp.python.ideas mirror. -- Terry Ja

Re: For loop comprehensions

2011-02-11 Thread Steven D'Aprano
On Fri, 11 Feb 2011 16:59:52 -0700, Ian Kelly wrote: > Why not allow the same thing in for-loop conditions? Because new syntax and new language features means more work. Somebody has to write the code, make sure that it doesn't break existing Python code, test it for bugs, change the document

Re: For loop comprehensions

2011-02-11 Thread Ian Kelly
On Fri, Feb 11, 2011 at 4:47 PM, Westley Martínez wrote: > No, too confusing. Then people'll want compound loops e.g.: > > for a in b if c while d else return x: >    print('Ha ha I'm so clever!') I've yet to see anybody arguing for while loops to be nested like that, but we already allow nested

Re: For loop comprehensions

2011-02-11 Thread Westley Martínez
On Fri, 2011-02-11 at 15:10 -0800, Benjamin S Wolf wrote: > It occurred to me as I was writing a for loop that I would like to > write it in generator comprehension syntax, eg. > > for a in b if c: > > rather than using one of the more verbose but allowable syntaxes: > > for a in (x for x in

Re: For loop comprehensions

2011-02-11 Thread Jon Clements
On Feb 11, 11:10 pm, Benjamin S Wolf wrote: > It occurred to me as I was writing a for loop that I would like to > write it in generator comprehension syntax, eg. > >   for a in b if c: > > rather than using one of the more verbose but allowable syntaxes: > >   for a in (x for x in b if c): > >  

For loop comprehensions

2011-02-11 Thread Benjamin S Wolf
It occurred to me as I was writing a for loop that I would like to write it in generator comprehension syntax, eg. for a in b if c: rather than using one of the more verbose but allowable syntaxes: for a in (x for x in b if c): for a in b: if not c: continue Python 3.1 does not suppo