List comprehension vs generator expression memory allocation

candide candide at free.invalid
Sun Sep 20 19:17:36 CEST 2009


Duncan Booth a écrit :

> Why are you slicing the result of range? Why not just pass appropriate 
> arguments to range or xrange directly?
> 

Why ? Guilty ignorance ;)


> def f(a,b,m):
> 	return xrange((a+m-1)//m*m, b, m)
> 


Nice code, furthermore giving the best execution time, thanks.



More information about the Python-list mailing list