你的
refDict
可能是错的。这个
in
关键字检查值是否在字典的关键字中。我相信你把你的话当作价值观。
我建议使用
set
而不是字典。
knownwords = set("dog", "cat")
knownwords.add("apple")
text = "The dog eats an apple."
for word in text.split(" "):
# to ignore case word is converted to lowercase
if word.lower() not in knownwords:
print word
# The
# eats
# an
# apple. <- doesn't work because of the dot