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.
--
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]
> # --
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
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