Check substring match of a word in a list of words

后端 未结 3 1288
旧时难觅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:51

    You could also create a single search string by concatenating all of the words in word_list into a single string:

    word = "with" 
    word_list = ' '.join(["without", "bla", "foo", "bar"])
    

    Then a simple in test will do the job:

    return word in word_list 
    

提交回复
热议问题