I'm searching for a list of terms in a file. I want to print the line number in the file where the term was found.
This is the code I'm using to find the term:
w = "wordlist.txt" d = "demofile.txt" keys = [key for key in (line.strip().lower() for line in open(w)) if key] with open(d) as f: print("File", w) for line in f: for key in keys: if key in line.lower(): print(key)
enumerate:for lineno, line in enumerate(f):. Keep in mind that this starts numbering from 0.enumerate, to never know about thestartparameter (because I never had to look up the documentation forenumerate).