python itertools

If you want the dot product with python. maybe or maybe not, it can be implemented as follows

a = [1, 2, 3]
b = [4, 5, 6]
result = 0
for i, j in zip(a,b):
result += i * j

but if you use itertools of python, you can write code as follows

import operator
a = [1, 2, 3]
b = [4, 5, 6]
result = sum(map(operator.mul, a, b))

Why do you know itertools.

  1. Code readability: As a simple example like dot product, the difference between two implementations is insignificant. But in the real world, more complexed list item with multiple for-loop make many developers tired.

Let's read the official document. this post is based on the document.

reference