Write a Python function that returns the sum of the pairwise

Write a Python function that returns the sum of the pairwise products of listA and listB. You should assume that listA and listB have the same length and are two lists of integer numbers. For example, if listA = [1, 2, 3] and listB = [4, 5, 6], the dot product is 1 astir 4 + 2 astir 5 + 3 astir 6, meaning your function should return 32

Solution

// dotproduct function uses sum and zip function, zip function is used to Make an iterator that aggregates elements from each of the list. and sum function add element of list parallel .

def dotproduct(ListA,ListB):
return sum(i*j for i, j in zip(ListA,ListB))

print dotproduct([1,2,3],[4,5,6])

 Write a Python function that returns the sum of the pairwise products of listA and listB. You should assume that listA and listB have the same length and are t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site