python - How to read just words, not full phrases -
i have code reads text file, , prints out each line containing keyword (entered input). however, whole phrase entered gets searched, not words them selves. e.g. enter
i have fast car
the whole phrase searched in file, not keywords, such fast, or car.
file = open("file.txt", "r") search= input("what searched? ") line in file: if search in line: print ("found" +line) file.close()
try this:
search = input("what searched? ").split() open("file.txt", "r") f: line in f: if any(word in line word in search): print ("found" + line)
Comments
Post a Comment