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
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to