我可以知道如何将多个字符串与多个列表匹配吗?我运行了代码,但它没有给我'BEC'作为结果,为什么?
a = ["A", "B", "C"]
b = ["AB","BB"]
c = ["ABC","BCD","BEC"]
av, bv, cv = 'B', 'AB', 'BEC'
for _a, _b, _c in zip(a,b,c):
if _a == av and _b == bv and _c == cv:
print cv # 'BEC'
答案 0 :(得分:0)
最简单的方法:
if a in a and bv in b and cv in c: print cv
all
方式使用:
all((av in a, bv in b, cv in c))
为了娱乐而改编的all
方式:
_lists = [a,b,c]
all(value in _lists[i] for i, value in enumerate([av,bv,cv]))
答案 1 :(得分:0)
from itertools import product
a = ["A", "B", "C"]
b = ["AB","BB"]
c = ["ABC","BCD","BEC"]
av, bv, cv = 'B', 'AB', 'BEC'
for _a, _b, _c in product(a,b,c):
if _a == av and _b == bv and _c == cv:
print cv # 'BEC'