I have a problem. I want to make a dictionary that translates english words to estonian. I started, but don’t know how to continue. Please, help.
Dictionary is a text document where tab separates english and estonian words.
file = open("dictionary.txt","r")
eng = []
est = []
while True :
lines = file.readline()
if lines == "" :
break
pair = lines.split("\t")
eng.append(pair[0])
est.append(pair[1])
for i in range......
Please, help.
For a dictionary, you should use the dictionary type which maps keys to values and is much more efficient for lookups. I also made some other changes to your code, keep them if you wish:
Mind that the reverse lookup (Estonian to English) is not so easy. If you need that, too, you might be better off creating a second dictionary variable with the reversed key-value mapping (
estToEngDict[pair[1]] = pair[0]) because lookup will be a lot faster than your list-based approach.