So I have a text file from which I am trying to extract certain lines which contain a specific word. The lines are want are lines which contain the word HEIGHT, however there is another category in my text file called AVERAGEHEIGHT. So when I run this code it extracts all lines that contain both HEIGHT and AVERAGEHEIGHT, where as I am only interested in HEIGHT. Is there a way to fix this?
Here is my line of code for this
open('height.txt','w').writelines([ line for line in open("Test1.txt") if "HEIGHT" in line])
Thanks in advance for any advice on the matter.