Accumulate , Range and Zeros

Dan Sommers 2QdxY4RzWzUUiLuE at potatochowder.com
Sat Jul 13 06:30:35 EDT 2019



On 7/13/19 5: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?

I see two things going on here.

(1) Don't type snippets of code and results from memory, or
in bits and pieces from an interactive session.  Copy and
paste exactly the code that ran and the output that it
produced.

(2) What is range(5)?  Okay, what is list(range(5))?  What
do you (the person) get when you multiply those five
integers together?

HTH,
Dan



More information about the Python-list mailing list