给出频率列表列表(参见示例)。如何获得列表中所有第n个成员的产品。 例如:
l1 = [1,2,3]
l2=[4,5,6]
output = [4,10,18]
如果列表的长度未知,我该如何完成此操作。请用pythonic方式回答,我很感激帮助!
示例数据:
[
[0.8507462686567164, 0.14925373134328357], [0.9870967741935484,
0.012903225806451613], [0.5833333333333334, 0.4166666666666667],
[0.4791666666666667, 0.5208333333333334], [0.9379084967320261,
0.06209150326797386], [0.9657320872274143, 0.03426791277258567],
[0.9914529914529915, 0.008547008547008548], [0.9050279329608939,
0.09497206703910614], [0.7660944206008584, 0.23390557939914164]
]
输出:
[product of 1st elements, product of 2nd elements, product of n elements]
答案 0 :(得分:0)
您可以尝试:
>>> l1 = [1,2,3]
>>> l2=[4,5,6]
>>> [x * y for x,y in zip(l1,l2)]
[4, 10, 18]