Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
Thanks Peter/Denis. I wasn't aware of genexp. I see how you have adapted the code to make it work, I'll adapt the same in my program. Good point about duplicating j , Denis, I guess I was happy to override the outer j as it was intermediate. On 17 March 2014 12:36, spir wrote: > On 03/17/2014 1

Re: [Tutor] Tutor Digest, Vol 121, Issue 42 nested "for"

2014-03-17 Thread fabu desay
python executes the first "for" and its condititions then the next "for". What i'm saying is that you should first deal with one as nested block codes ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.pyt

[Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+str(j)) else: j=int("9"+str(j))

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread spir
On 03/17/2014 11:22 AM, Jignesh Sutar wrote: Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+st

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Peter Otten
Peter Otten wrote: > [locals()] does not capture > the loop vars of genexps (all pythons) and listcomps (python3). Sorry, I was totally wrong on that one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://m

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Peter Otten
Jignesh Sutar wrote: > Is it possible to get two nested for statements followed by a nested > if/else statement all into a single list comprehension ie. the equivalent > of the below: > > > for i in xrange(1,20): > for j in xrange(1,10): > if j<6: > j=int("8"+str(j)) >

[Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Jignesh Sutar
Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+str(j)) else: j=int("9"+str(j))