Accumulate , Range and Zeros
On 2019-07-13 11:54 AM, Abdur-Rahmaan Janhangeer wrote:
> Given this snippet
> from itertools import *
> import operator
> x = [1, 2, 3] # [0, 1, 2, 3, ..., 10]
> y = accumulate(x, operator.mul)
> 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.