Check exact match of a word in a list of words
Posted
by
Flake
on Stack Overflow
See other posts from Stack Overflow
or by Flake
Published on 2011-11-26T00:31:20Z
Indexed on
2011/11/26
1:50 UTC
Read the original article
Hit count: 90
python
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 in set(list)
, but it is not yielding the wanted result due to the fact in
is matching string rather than item. That is to say, "with"
is a match in any of the words in the word_list
but still if "with" in set(list)
will say True
.
What is a simpler way for doing this check than manually iterate over the list
?
© Stack Overflow or respective owner