有没有最快的方法来执行以下 python 代码:
L1 = [1,1,1,1,0,0]
L2 = [0,0,1,1,0,1]
D1 = [0.03,0.04,0.01,0.02,0.01,0.02]
D2 = [0.05,0.01,0.03,0.07,0.12,0.41]
a = 0
b = 0
for l1,l2,d1,d2 in zip(L1,L2,D1,D2):
if l1 == 1:
a += d1
if l2 == 1:
b += d2
L1、L2、D1 和 D2 的长度相同,大约有 4000 个条目。
谢谢!