Accumulate , Range and Zeros
Frank Millman
frank at chagford.com
Sat Jul 13 06:49:45 EDT 2019
On 2019-07-13 11:54 AM, Abdur-Rahmaan Janhangeer wrote:
> Greetings,
>
> Given this snippet
>
> from itertools import *
> import operator
>
>
> x = [1, 2, 3] # [0, 1, 2, 3, ..., 10]
>
> y = accumulate(x, operator.mul)
>
> print(list(y))
>
> why does x = list(range(5)) produces only zeros?
>
That is an easy one.
By default, range() starts from 0. Anything multiplied by 0 equals 0. So
you can multiply as many numbers as you like, if the first one is 0, the
rest will also be 0.
QED
Frank Millman
More information about the Python-list
mailing list