Check if a Python list item contains a string inside another string according to this question and in first answer, instead of a string, I want to loop in list
I have tried this but it didn't work
matching = [s for s in fd if [s for s in chht] in fd]
for more declare
I have list 1=["he","bell","go"] list=["o","e"]
so the actual output is:
words has o letter are ["go"]
words has e letter are ["he","bell"]
Try using 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.