Вы можете использовать наборы, чтобы получить эту информацию:
text = """I have a list of strings. I would like to check if any of the strings of
that list appears on a bigger document saved on a string var.
I know this can easily be done with a loop, but I will be doing this operation so
many times (and another loops apart of this) so I was wondering if there is any
more efficient way to do it instead of a for loop."""
words = set(["would","this","do","if","supercalifragelisticexpialigetic"])
text_words = text.split()
# show all that are in it
print(words.intersection(text_words)) # words & set(text_words)
# show all that are not in it
print(words.difference(text_words)) # words - set(text_words)
Выход:
set(['this', 'do', 'would', 'if']) # words & set(text_words)
set(['supercalifragelisticexpialigetic']) # words - set(text_words)
Чтобы получить счет также:
from collections import Counter
counted = Counter(text_words)
for w in words:
print(w, counted.get(w))
Выход:
do 1
would 1
supercalifragelisticexpialigetic None
if 2
this 2