python - 对于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"]
解决方案
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
推荐阅读
- ruby-on-rails - Rails 5无法存储在数据库中
- pandas - Python读取压缩文件夹中子文件夹内的csv文件
- r - 剧情:如何改变休息时间?
- android - 我怎样才能reslove方法'toMap'在null上被调用?
- java - JavaSWT 应用程序在 Eclipse 中工作但在终端中不工作
- excel - 用另一个工作表中的数据动态填充下一个空行
- javascript - 使用 formik 从字段名称列表中显示输入字段
- opencv - 如何从图像中提取嘈杂的连接组件?
- android - Kotlin 中的 DialogFragment.onDismiss() 空指针异常
- visual-studio-code - 加号登录 VS Code Explorer 树视图