This combination is called the Cartesian product. I would use itertools.productfor this, which can easily handle more than two lists if you want.
First, here's a short demo that shows how to get all the pairs and how to use the tuple assignment to capture the individual elements of the subscription pairs.
from itertools import product
a = [[1,2],[3,4],[7,10]]
b = [[8,6],[1,9],[2,1],[8,8]]
for (u0, u1), (v0, v1) in product(a, b):
print(u0, u1, v0, v1)
Exit
1 2 8 6
1 2 1 9
1 2 2 1
1 2 8 8
3 4 8 6
3 4 1 9
3 4 2 1
3 4 8 8
7 10 8 6
7 10 1 9
7 10 2 1
7 10 8 8
sum , .
total = sum(u0 * v0 + u1 * v1 for (u0, u1), (v0, v1) in product(a, b))
print(total)
593
, , Prune.
-, .;)
a = [[1,2],[3,4],[7,10]]
b = [[8,6],[1,9],[2,1],[8,8]]
print(sum([u*v for u,v in zip(*[[sum(t) for t in zip(*u)] for u in (a, b)])]))
593
, ,
(1 + 3 + 7) * (8 + 1 + 2 + 8) + (6 + 9 + 1 + 8) * (2 + 4 + 10)
.
for u in (a, b):
for t in zip(*u):
print(t)
(1, 3, 7)
(2, 4, 10)
(8, 1, 2, 8)
(6, 9, 1, 8)
,
partial_sums = []
for u in (a, b):
c = []
for t in zip(*u):
c.append(sum(t))
partial_sums.append(c)
print(partial_sums)
[[11, 16], [19, 24]]
, . , zip .
total = 0
for u, v in zip(*partial_sums):
print(u, v)
total += u * v
print(total)
11 19
16 24
593