I have a list of words in a txt file and thousands of words in a list. How can I search for them and add them in a new list if they are found
The words.txt file contain 100k words. my_list contain 4k words.
Currently I do this.
my_list = [hello, hi, hey, ho, wow, .....]
with open("words.txt") as f:
lines = [line.rstrip() for line in f]
words_in_lines = []
for i in my_list:
if i in lines:
words_in_lines.append(i)
This is non ending, it's not executing as there are too many words in the words list.