Re: nested list comprehension and if clauses

2007-06-27 Thread Jyotirmoy Bhattacharya
On Jun 28, 10:53 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Jyotirmoy Bhattacharya <[EMAIL PROTECTED]> wrote: > > print [(m,n) for m in range(5) for n in multab(m) if m>2] > > I was wondering if there is some way to write the if-clause so that it > > is 'hoisted' out of the inner loop and the m

Re: nested list comprehension and if clauses

2007-06-27 Thread Alex Martelli
Paul Rubin wrote: > [EMAIL PROTECTED] (Alex Martelli) writes: > > > print [(m,n) for m in range(5) for n in multab(m) if m>2] > > Sure, just place the if clause where it needs to apply (between the two > > for clauses) [apart from the fact that this example is best expre

Re: nested list comprehension and if clauses

2007-06-27 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: > > print [(m,n) for m in range(5) for n in multab(m) if m>2] > Sure, just place the if clause where it needs to apply (between the two > for clauses) [apart from the fact that this example is best expressed by > using range(3,5), as somebody already said;-

Re: nested list comprehension and if clauses

2007-06-27 Thread Alex Martelli
Jyotirmoy Bhattacharya <[EMAIL PROTECTED]> wrote: > I'm a newcomer to Python. I have just discovered nested list > comprehensions and I need help to understand how the if-clause > interacts with the multiple for-clauses. I have this small program: > > def multab(n): > print 'multab',n > r

Re: nested list comprehension and if clauses

2007-06-27 Thread Paul Rubin
Jyotirmoy Bhattacharya <[EMAIL PROTECTED]> writes: > print [(m,n) for m in range(5) for n in multab(m) if m>2] > I was wondering if there is some way to write the if-clause so that it > is 'hoisted' out of the inner loop and the multab function is not > called at all for m=0,1,2. That would seem t

nested list comprehension and if clauses

2007-06-27 Thread Jyotirmoy Bhattacharya
I'm a newcomer to Python. I have just discovered nested list comprehensions and I need help to understand how the if-clause interacts with the multiple for-clauses. I have this small program: def multab(n): print 'multab',n return [n*i for i in range(5)] print [(m,n) for m in range(5) for