Stack Overflow is not code writing service, We try to help people only when they try to do something and stuck , I am not giving an exact solution but I will show you how you can achieve your goal, and rest is your homework:
Good answer by @Srikar Appalaraju
#Sample 1 - elucidating each step but not memory efficient
lines = []
with open("C:\name\MyDocuments\numbers") as file:
for line in file:
line = line.strip() #or some other preprocessing
lines.append(line) #storing everything in memory!
#Sample 2 - a more pythonic and idiomatic way but still not memory efficient
with open("C:\name\MyDocuments\numbers") as file:
lines = [line.strip() for line in file]
#Sample 3 - a more pythonic way with efficient memory usage. Proper usage of with and file iterators.
with open("C:\name\MyDocuments\numbers") as file:
for line in file:
line = line.strip() #preprocess line
doSomethingWithThisLine(line) #take action on line instead of storing in a list. more memory efficient at the cost of execution speed.
Example :
with open('dictionary.txt','r') as f:
#for reading line by line
for line in f:
print(line)
#reading whole file once
print(f.read())
Now how to check word in file :
Using python 'in'
operator
#checking word
if 'some_word' in line:
print(True)
else:
print(False)
Now try something and when you stuck then ask help, instead of asking to write code.