Re: conditional for-statement

2009-08-26 Thread seb
On Aug 25, 11:57 pm, Piet van Oostrum wrote: > You can also say: > [x+y for x in range(3) for y in range(4) if x < y] > If you want to write this as a loop you have to put the for's on > separate lines separated by colons, so why not the if also? Or would you > also like to have the for's on one l

Re: conditional for-statement

2009-08-25 Thread Piet van Oostrum
> seb (s) wrote: >s> i am still a bit puzzle by the following. >s> I read in >http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generators >s> """Python 3.0 unifies all collection types by introducing dict and set >s> comprehensions, similar to list comprehensions: > [ n*n for

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 25, 10:46 pm, Falcolas wrote: > On Aug 25, 1:58 pm, seb wrote: > > > On Aug 25, 9:42 pm, Falcolas wrote: > > > On Aug 25, 11:25 am, seb wrote: > > > So, what part of the statement does the "if" statement belong to; > > > particularly a concern considering this is valid python: > > > > fo

Re: conditional for-statement

2009-08-25 Thread Falcolas
On Aug 25, 1:58 pm, seb wrote: > On Aug 25, 9:42 pm, Falcolas wrote: > > On Aug 25, 11:25 am, seb wrote: > > So, what part of the statement does the "if" statement belong to; > > particularly a concern considering this is valid python: > > > for x in y if y else z: > >     body > > can this be d

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 25, 9:42 pm, Falcolas wrote: > On Aug 25, 11:25 am, seb wrote: > > > > > We could as consistenly explain that the syntax > > > for n in range(10) if n%3==0: > >   body > > > means > > > for n in range(10): > >   if n%3==0: > >     body > > > This syntax has also the benefit of avoiding an

Re: conditional for-statement

2009-08-25 Thread Falcolas
On Aug 25, 11:25 am, seb wrote: > We could as consistenly explain that the syntax > > for n in range(10) if n%3==0: >   body > > means > > for n in range(10): >   if n%3==0: >     body > > This syntax has also the benefit of avoiding an extra level of > indentation (the one for the if) that bears

Re: conditional for-statement

2009-08-25 Thread Rami Chowdhury
We could as consistenly explain that the syntax for n in range(10) if n%3==0: body means for n in range(10): if n%3==0: body This syntax has also the benefit of avoiding an extra level of indentation (the one for the if) that bears no real meaning on a structural level. I'm sorry, I

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 24, 12:05 am, Mel wrote: > seb wrote: > > On Aug 23, 6:18 pm, John Posner wrote: > [ ... ] > >> How about using a generator expression instead of a list? > > >> for i in (x for x in range(10) if x > 5): > >> print i > > >> -John > > > Indeed, but we could have the same syntax than for gene

Re: conditional for-statement

2009-08-25 Thread seb
On Aug 23, 11:02 pm, Chris Rebert wrote: > On Sun, Aug 23, 2009 at 1:36 PM, seb wrote: > > On Aug 23, 6:18 pm, John Posner wrote: > >> >> Hi, > > >> >> i was wondering if there is a syntax alike: > > >> >> for i in range(10) if i > 5: > >> >>     print i > > >> > You can write > > >> > for i in f

Re: conditional for-statement

2009-08-24 Thread Bruno Desthuilliers
seb a écrit : Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i equivalent to for i in (for i in range(10) if i>5): print i what about : for i in range(6, 10): print i More seriously: for i in range(10): if i > 5: print i -- h

Re: conditional for-statement

2009-08-23 Thread Mel
seb wrote: > On Aug 23, 6:18 pm, John Posner wrote: [ ... ] >> How about using a generator expression instead of a list? >> >> for i in (x for x in range(10) if x > 5): >> print i >> >> -John > > Indeed, but we could have the same syntax than for generators but > directly in the for statement as

Re: conditional for-statement

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 1:36 PM, seb wrote: > On Aug 23, 6:18 pm, John Posner wrote: >> >> Hi, >> >> >> i was wondering if there is a syntax alike: >> >> >> for i in range(10) if i > 5: >> >>     print i >> >> > You can write >> >> > for i in filter(lambda i: i > 5, range(10)): >> >     print i >>

Re: conditional for-statement

2009-08-23 Thread seb
On Aug 23, 10:36 pm, seb wrote: > On Aug 23, 6:18 pm, John Posner wrote: > > > > > > > >> Hi, > > > >> i was wondering if there is a syntax alike: > > > >> for i in range(10) if i > 5: > > >>     print i > > > > You can write > > > > for i in filter(lambda i: i > 5, range(10)): > > >     print i

Re: conditional for-statement

2009-08-23 Thread seb
On Aug 23, 6:18 pm, John Posner wrote: > >> Hi, > > >> i was wondering if there is a syntax alike: > > >> for i in range(10) if i > 5: > >>     print i > > > You can write > > > for i in filter(lambda i: i > 5, range(10)): > >     print i > > > but > > > for i in range(10): > >     if i > 5: > >  

Re: conditional for-statement

2009-08-23 Thread John Posner
Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i You can write for i in filter(lambda i: i > 5, range(10)): print i but for i in range(10): if i > 5: print i it' better readable, and for i in range(6,10): print i it's e

Re: conditional for-statement

2009-08-23 Thread David
Il Sun, 23 Aug 2009 01:09:04 -0700 (PDT), seb ha scritto: > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: > print i You can write for i in filter(lambda i: i > 5, range(10)): print i but for i in range(10): if i > 5: print i it' be

Re: conditional for-statement

2009-08-23 Thread Francesco Bochicchio
On Aug 23, 10:09 am, seb wrote: > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: >     print i > > equivalent to > > for i in (for i in range(10) if i>5): >     print i > > sebastien AFAIK, no syntax fo that. But the standard syntax is not too different: for

Re: conditional for-statement

2009-08-23 Thread Benjamin Peterson
seb gmail.com> writes: > > Hi, > > i was wondering if there is a syntax alike: > > for i in range(10) if i > 5: > print i for i in range(10): if i > 5: print i -- http://mail.python.org/mailman/listinfo/python-list

conditional for-statement

2009-08-23 Thread seb
Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i equivalent to for i in (for i in range(10) if i>5): print i sebastien -- http://mail.python.org/mailman/listinfo/python-list