python - multiply and add each element in list a with list b

前端 未结 3 724
灰色年华
灰色年华 2021-01-29 10:53

function:

def unique_common(a, b):

I have two lists, lets say:

a = [2, 3, 5, 7, 9] 

and another list

b = [5, 8         


        
3条回答
  •  执念已碎
    2021-01-29 11:50

    And also you can use map :

    >>> a = [2, 3, 5, 7, 9] 
    >>> b = [5, 8, 4, 1, 11]
    >>> sum(map(lambda x: x[0] * x[1], zip(a, b)))
    160
    

提交回复
热议问题