1

有没有更简单的方法:

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]

4

2 回答 2

8
ab = [any(x) for x in zip(cd, ca, cp)]
于 2012-10-02T14:49:50.547 回答
0

您可以使用列表理解

ab = [cd[x] or ca[x] or cp[x] for x in range(len(cd))]
于 2012-10-02T14:51:06.643 回答