What is a list compression in Python?

Gib Bogle g.bogle at auckland.no.spam.ac.nz
Mon Jan 18 21:48:59 EST 2010


Kit wrote:
> Thank you so much guys.
> 
> Just out of curiosity: can I do something like this to "square all
> even numbers in the range 1-10"?
> print [x^2 for x in range (1,11) if x % 2 == 0]

Why not try it?



More information about the Python-list mailing list