Search notes:

Python: sum

#!/usr/bin/python3

nums = [1, 2, 3, 4]

print(sum(nums    )) # 10
print(sum(nums,  5)) # 15
Github repository about-python, path: /built-in/functions/sum/basic.py

Sum of pairwise mulitplication

The following script uses zip to sum up the pairwise multiplication of elements of two lists.
It prints 34, which is 1*2 + 5*4 + 4*3:
x = [1, 5, 4]
y = [2, 4, 3]

p = sum(x*y for x,y in zip(x,y))

print(p)
Github repository about-python, path: /built-in/functions/sum/pairwise.py

See also

Python: Built in functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199202, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/built-in/functions/sum/index(58): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78