首页 > 解决方案 > 对于list1的任何项目,如果它是python中的list2

问题描述

根据此问题检查 Python 列表项是否包含另一个字符串中的字符串,并且在第一个答案中,我想在列表中循环,而不是字符串

我已经尝试过了,但它没有用

matching = [s for s in fd if [s for s in chht] in fd]

更多声明

我有列表 1=["he","bell","go"] list=["o","e"]

所以实际输出是:

单词有 o 字母是 ["go"]

单词有 e 字母是 ["he","bell"]

标签: python

解决方案


wordList = ["he", "bell", "go"]
searchCharList = ["o", "e"]
matching = [word for word in wordList for char in searchCharList if char in word]

print matching
>>> ['he', 'bell', 'go']

print bool(matching)
>>> True

推荐阅读