繁体   English   中英

对于 list1 的任何项目,如果它是 python 中的 list2

[英]for any item of list1 if it is list2 in python

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

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

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

更多声明

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

所以实际的 output 是:

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

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

尝试使用any

matching = any([s in chht for s in fd])
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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM