This sounds like it has been asked before but I cannot find anything that helps me.
My code is:
with open('file directory', 'r') as file:
data = []
for line in file:
for word in line.split():
data.append(str(word))
last_word = str(data[-1])
if last_word == "bobby":
print("yes")
else:print("no")
I want to know if the last element of the text file which I turned into a list matches a string, for example "bobby". Instead, what I get is basically a counter of how many times bobby was mentioned in the list.
Terminal:
yes
yes
yes