What is a list compression in Python?

MRAB python at mrabarnett.plus.com
Mon Jan 18 19:50:42 EST 2010


Kit wrote:
> Oops...
> 
>> print [x^2 for x in range (1,11) if x % 2 == 0]
> print [x^2 for x in range (1,10) if x % 2 == 0]
> 
The start is inclusive and the end is exclusive. This is a general rule
in Python. In fact, there's only one exception that I know of:
randint(a, b) in the 'random' module.




More information about the Python-list mailing list