Reputation: 13
I am having an issue with an if statement regarding an item in a list. Here is the code I am using
score = 0
for j in range(0,1):
for k in range(0,len(split)):
keyword = str(split[k][1])
words = texts[j]
print(keyword,words)
if str(keyword) in list(words):
print("true")
score = score + float(split[k][0])
else:
print("false")
print(score)
Here is the portion of the output where the statement is visibly wrong. What is wrong in the situation?
"now" ['anonym', 'now'] false 0
Upvotes: 0
Views: 8599
Reputation: 9597
Your keyword
is "now"
- INCLUDING the quote marks. It indeed does not exist in words
, which only includes words without quote marks. Either fix whatever problem with the source of the data is adding those quotes, or strip them off with something like keyword = keyword.strip('"')
.
Upvotes: 1