-3

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"]

oliver
  • 1
  • 1

2 Answers2

0

Try using any:

matching = any([s in chht for s in fd])
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • I dont know but it returned on false look for 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"] – oliver Nov 06 '19 at 09:45
0
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
VegaS
  • 1
  • 1
  • Thanks worked for me I want to upvote but this notice came to me – oliver Nov 06 '19 at 10:33
  • Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score. – oliver Nov 06 '19 at 10:33