Reputation: 445
I have a txt file with several thousand words. However, when I try and pull them into a dictionary
variable in python 3.7 some words do not appear.
The dictionary file is here
For example:
dictionary = {}
with open("en-dict.txt", "r", encoding="utf8") as file:
for line in file:
line = file.readline().strip()
dictionary[line] = 0
if "eat" in dictionary:
print("Yes")
Why is this happening? Thanks
Upvotes: 0
Views: 87
Reputation: 794
try with this code:
dictionary = {}
with open("en-dict.txt", "r", encoding="utf8") as file:
for line in file:
dictionary[line.split("\n")[0]] = 0
print(dictionary)
if "eat" in dictionary:
print("Yes")
Upvotes: 1