Hi everyone,
So I have revised my code and hope you guys can help me out. My intention is to compare each words from user input to words in a file and print only words not exist from user input. My code is as shown below. I apologized for not know how to insert code correctly.
I only need to pull the words not exist from user input. What I want the output to print is:
So I have revised my code and hope you guys can help me out. My intention is to compare each words from user input to words in a file and print only words not exist from user input. My code is as shown below. I apologized for not know how to insert code correctly.
sentence = input("Enter a sentence: ")
text = sentence.split()
for counter in text:
# print (str.lower(counter))
with open('data.txt') as file:
content = file.read()
for counter in content:
if text in content:
continue
if text not in content:
print(counter)
print('These words not in list')data.txtOutput:apples
oranges
bananas
kiwisOutput:Error:Enter a sentence: i love apples
Traceback (most recent call last):
File "test.py", line 13, in <module>
if text in content:
TypeError: 'in <string>' requires string as left operand, not listI am not sure how to handle the error.I only need to pull the words not exist from user input. What I want the output to print is:
Output:i
love
These words not in listPlease advise.
