>>> lst = [1, 2, 3, 4] >>> >>> sum(i * i for i in lst) 30 >>>
>>> lst1 = [1, 2, 3, 4] >>> lst2 = [5, 6, 7, 8] >>> >>> sum(i * j for i, j in zip(lst1, lst2)) 70 >>>
>>> def dot(a, b): ... return sum(i * j for i, j in zip(a, b)) ... >>> a = [1, 2, 3, 4] >>> b = [5, 6, 7, 8] >>> >>> dot(a, a) 30 >>> dot(a, b) 70 >>>