I want to check two words exist in the same list simultaneously.
For example
I have a word list just like
word_list = [I have a dream, I am a dreamer]
and have a dataframe named df like
df
# word1 word2
# have dream
# basketball player
I want to check two words exist in the same list simultaneously. So I wrote my code like this
for index, row in df.iterrows():
text = []
tokenized = word_list.split()
for tokenized_word in tokenized:
if row["word1"] == tokenized_word:
for tokenized_word in tokenized:
if row["word2"] == tokenized_word:
text.append(word_list)
If the list have many many elements and the dataframe has many words, it would spend many time to run this code. Anyway to faster my code?