a = ['french', 'english']
b = ['(portuguese; french)', '(english)']我想要比较两个列表,作为回报,我想要匹配的索引
我试过了:
matches = list([i for i, item in enumerate(a) if item in b]+[i for i, item in enumerate(b) if item in a])但结果却是一张空名单
发布于 2016-12-08 20:57:08
你需要这个..。
b = ['(portuguese, french)', '(english)']
a = ['french', 'english']
matching = [i for i, x in enumerate(b) if any(thing in x for thing in a)]
print matching
output: [0, 1]https://stackoverflow.com/questions/41039845
复制相似问题