Reputation: 419
When I execute the following code, for some reason I don't get a match on some of the words and I'm not sure why. Here is the copy of the text which is read in (it is 5 words each followed by a newline character as follows):
File:
cackle
cage
cake
calibrate
call
Code:
verb_list = set()
with open ("/Users/docs/verbs") as f:
for item in f:
verb_list.add(item)
print("verbs: " + str(len(verb_list)))
if ("call\n" in verb_list):
print("true")
else:
print("false")
if ("cage\n" in verb_list):
print("true")
else:
print("false")
Output:
verbs: 5
true
false
Any ideas what I am doing wrong?
Upvotes: 0
Views: 57
Reputation: 216
Cage has an extra space after it. Also verb_list is not defined. Try using verbs.
Upvotes: 3