nested list comprehension and if clauses
Paul Rubin
http
Thu Jun 28 02:03:09 EDT 2007
aleax at mac.com (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;-)].
You mean
print [(m,n) for m in range(5) if m > 2 for n in multab(m)]
Heh. I didn't realize you could do that. Thanks.
More information about the Python-list
mailing list