Re: Accumulate , Range and Zeros

2019-07-13 Thread Abdur-Rahmaan Janhangeer
oh not a real bug, i thought the effect had to do with generator working
rather a simple times 0

Abdur-Rahmaan Janhangeer
Mauritius

On Sat, 13 Jul 2019, 16:24 Chris Angelico,  wrote:

> On Sat, Jul 13, 2019 at 10:02 PM Abdur-Rahmaan Janhangeer
>  wrote:
> >
> > @Thomas thought was a generator bug since instead of returning the usual
> > nums it was returning 0 0 0 ...
>
> When you find a bug or strange bit of behaviour, first make sure you
> can reproduce it. Then create a small, self-contained program, just
> enough to demonstrate what's going on. Post that code. Don't make us
> guess :)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accumulate , Range and Zeros

2019-07-13 Thread Chris Angelico
On Sat, Jul 13, 2019 at 10:02 PM Abdur-Rahmaan Janhangeer
 wrote:
>
> @Thomas thought was a generator bug since instead of returning the usual
> nums it was returning 0 0 0 ...

When you find a bug or strange bit of behaviour, first make sure you
can reproduce it. Then create a small, self-contained program, just
enough to demonstrate what's going on. Post that code. Don't make us
guess :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accumulate , Range and Zeros

2019-07-13 Thread Abdur-Rahmaan Janhangeer
@Thomas thought was a generator bug since instead of returning the usual
nums it was returning 0 0 0 ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accumulate , Range and Zeros

2019-07-13 Thread Thomas Jollans
On 13/07/2019 11:54, 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?

What would you expect it to produce?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accumulate , Range and Zeros

2019-07-13 Thread Abdur-Rahmaan Janhangeer
@Frank

So simple. Thanks!

Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accumulate , Range and Zeros

2019-07-13 Thread Dan Sommers




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


Re: Accumulate , Range and Zeros

2019-07-13 Thread Frank Millman

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