RE: sum() vs. loop

2021-10-13 Thread Avi Gross via Python-list
worry the original might be changed out from under. My apologies if it was understood to mean I had shown it was copied. -Original Message- From: Python-list On Behalf Of Stefan Ram Sent: Tuesday, October 12, 2021 9:49 PM To: python-list@python.org Subject: Re: sum() vs. loop &quo

Re: sum() vs. loop

2021-10-13 Thread Oscar Benjamin
On Mon, 11 Oct 2021 at 23:00, Christian Gollwitzer wrote: > > Am 10.10.21 um 10:49 schrieb Steve Keller: > > I have found the sum() function to be much slower than to loop over the > > operands myself: > > > > def sum_products(seq1, seq2): > > return sum([a * b for a, b in zip(seq1, seq2)]) >

Re: Re: sum() vs. loop

2021-10-12 Thread Chris Angelico
On Wed, Oct 13, 2021 at 12:36 PM Avi Gross via Python-list wrote: > > Alan, > > I am also wondering about that zip() function call to bind the two lists > into a sort of iterator object. Presumably that calls the iterator N times. > I did a test where I made two list called A and B and used zip to

RE: Re: sum() vs. loop

2021-10-12 Thread Avi Gross via Python-list
. -Original Message- From: Python-list On Behalf Of Alan Gauld Sent: Tuesday, October 12, 2021 6:56 PM To: python-list@python.org Subject: Fwd: Re: sum() vs. loop On 10/10/2021 09:49, Steve Keller wrote: > I have found the sum() function to be much slower than to loop over > the op

Re: sum() vs. loop

2021-10-12 Thread Christian Gollwitzer
Am 12.10.21 um 05:41 schrieb Dan Stromberg: On Mon, Oct 11, 2021 at 2:54 PM Steve Keller wrote: I have found the sum() function to be much slower than to loop over the operands myself: def sum_products(seq1, seq2): return sum([a * b for a, b in zip(seq1, seq2)]) def sum_products2(seq1,

Fwd: Re: sum() vs. loop

2021-10-12 Thread Alan Gauld
On 10/10/2021 09:49, Steve Keller wrote: > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > s

Re: sum() vs. loop

2021-10-11 Thread Dan Stromberg
On Mon, Oct 11, 2021 at 2:54 PM Steve Keller wrote: > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b

Re: sum() vs. loop

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 9:02 AM Stefan Ram wrote: > > Steve Keller writes: > >Now completely surprised. > > I have observed that here the generator-based sum() call > is slower if both seq1 and seq2 have a length of 1000, but > faster if both seq1 and seq2 have 1000 entries each > (wi

Re: sum() vs. loop

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 8:55 AM Steve Keller wrote: > > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b

Re: sum() vs. loop

2021-10-11 Thread Steve Keller
Christian Gollwitzer writes: > > def sum_products(seq1, seq2): > > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > > sum = 0 > > for a, b in zip(seq1, seq2): > > sum += a * b > > return sum > > [...] > > The first version construct

Re: sum() vs. loop

2021-10-11 Thread Christian Gollwitzer
Am 10.10.21 um 10:49 schrieb Steve Keller: I have found the sum() function to be much slower than to loop over the operands myself: def sum_products(seq1, seq2): return sum([a * b for a, b in zip(seq1, seq2)]) def sum_products2(seq1, seq2): sum = 0 for a, b in zip(seq1, seq2):