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
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):
sum += a * b
return sum
In a program
"Dieter Maurer" writes:
> Steve Keller wrote at 2021-9-24 11:48 +0200:
> >Why do some built-in Python functions feel so differently:
>
> Because the typical use cases are different
>
> [...]
>
> >while other functions like set.union() and set.intersect
Why do some built-in Python functions feel so differently:
For example sum(), all(), any() expect exactly one argument which is a
sequence to operate on, i.e. a list, an iterator or a generator etc.
sum([1,2,3,4])
sum(range(1, 101))
sum(2**i for i in range(10))
all([True, False])
Just a short style question: When returning multiple return values, do
you use parenthesis?
E.g. would you write
def foo():
return 1, 2
a, b = foo()
or do you prefer
def foo():
return (1, 2)
(a, b) = foo()
Steve
--
https://mail.python.org/mailman/listinfo/py
I am trying to plot a live signal using matplotlib and it really
drives me crazy. I have tried dozens of variants, with and without
interactive (plt.ion()), with animation.FuncAnimation and doing things
by hand, calling plt.show() and/or plt.draw() but nothing works as
expected. One problem is th
Cancel ill-formated article
--
https://mail.python.org/mailman/listinfo/python-list
I wonder why iterators do have an __iter__() method? I thought
iterable objects would have an __iter__() method (but no __next__())
to create an iterator for it, and that would have the __next__()
method but no __iter__().
$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5
I have looked at generators, generator expressions, and iterators and
I try to get more familiar with these.
1. How would I loop over all (with no upper bound) integers or all
powers of two, for example?
In C it would be
for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... }
I
I have looked at generators, generator expressions, and iterators and
I try to get more familiar with these.
1. How would I loop over all (with no upper bound) integers or all
powers of two, for example?
In C it would be
for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... }
I
Why do the integers 0 and 1 compare equal to the boolean values False
and True and all other integers to neither of them?
$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
11 matches
Mail list logo