Check substring match of a word in a list of words

后端 未结 3 1294
旧时难觅i
旧时难觅i 2021-01-06 20:30

I want to check if a word is in a list of words.

word = \"with\"
word_list = [\"without\", \"bla\", \"foo\", \"bar\"]

I tried if word

3条回答
  •  无人及你
    2021-01-06 20:56

    You could do:

    found = any(word in item for item in wordlist)
    

    It checks each word for a match and returns true if any are matches

提交回复
热议问题