Re: List comprehension vs generator expression memory allocation

2009-09-21 Thread candide
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. --

Re: List comprehension vs generator expression memory allocation

2009-09-21 Thread Duncan Booth
candide wrote: > Each of the following two functions mult1() and mult2() solves the > question : > > > # - > def mult1(a,b,m): > return (x for x in range(a,b)[(m-a%m)%m:b:m]) > > def mult2(a,b,m): > return range(a,b)[(m-a%m)%m:b:m] > # --

Re: List comprehension vs generator expression memory allocation

2009-09-20 Thread Dave Angel
Jon Clements wrote: On 20 Sep, 14:35, candide wrote: Let's code a function allowing access to the multiples of a given integer (say m) in the range from a to b where a and b are two given integers. For instance, with data input a,b,m, 42, 5 the function allows access to : 20 25 30 35 40

Re: List comprehension vs generator expression memory allocation

2009-09-20 Thread Jon Clements
On 20 Sep, 14:35, candide wrote: > Let's code a function allowing access to the multiples of a given > integer (say m) in the range from a to b where a and b are two given > integers. For instance, with data input > > a,b,m=17, 42, 5 > > the function allows access to : > > 20 25 30 35 40 > > Each

List comprehension vs generator expression memory allocation

2009-09-20 Thread candide
Let's code a function allowing access to the multiples of a given integer (say m) in the range from a to b where a and b are two given integers. For instance, with data input a,b,m=17, 42, 5 the function allows access to : 20 25 30 35 40 Each of the following two functions mult1() and mult2()