有没有更简单的方法:
cd = [False,False,True]
ca = [False,False,False]
cp = [False,True,True]
ab[0] = cd[0] or ca[0] or cp[0]
ab[1] = cd[1] or ca[1] or cp[1]
ab[2] = cd[2] or ca[2] or cp[2]
要得到[False,True,True]
有没有更简单的方法:
cd = [False,False,True]
ca = [False,False,False]
cp = [False,True,True]
ab[0] = cd[0] or ca[0] or cp[0]
ab[1] = cd[1] or ca[1] or cp[1]
ab[2] = cd[2] or ca[2] or cp[2]
要得到[False,True,True]
ab = [any(x) for x in zip(cd, ca, cp)]
您可以使用列表理解:
ab = [cd[x] or ca[x] or cp[x] for x in range(len(cd))]