I have a log file of a conversation. I want to search the file for certain keywords which I have assigned but the log file may contain uppercase, lowercase and title case sensitive words of the keyword I am searching.
I can pull outlines which have the keyword in lower case but can't get the uppercase or title case versions of the word. How can I solve this?
I have tried using
if (words.title() and words.lower()) in line:
print (searchInLines[i])
but that doesn't seem to work.
keywords=['bimbo', 'qualified', 'tornadoes', 'alteryx', 'excel', 'manchester']
with open("recognition_log.txt", "r", encoding="utf8") as f:
searchInLines = f.readlines()
f.close()
for words in keywords:
for i, line in enumerate(searchInLines):
if (words.title() and words.lower()) in line:
print (searchInLines[i])
For example, the log file contains the following sentence:
"Manchester United played Barcelona yesterday, however, the manchester club lost"
I have "manchester" in my keywords so it will pick up the second one but not the first one.
How can I recognise both?
Thanks in Advance!