Когда я печатаю словарь, кажется, опускается более половины слов. Все слова имеют длину более 2 символов, поэтому должны быть помещены в их собственный ключ в словаре, но, по-видимому, игнорируются. Для проверки я сравнил файл с теми же словами, что и в словаре. 36 слов были найдены, а 45 пропущены.
Слова, которых нет в словаре.
Словарь с первыми двумя буквами. слова.
d = {}
#Opens the dictionary file from variable.
with open(dictionary, 'r') as f:
#iterates through each line
for line in f:
line_data = f.readline().strip()
#Gets the first to letters of the word to act as key
first_two = line_data[0:2]
#Checks if line is empty
if line_data is None:
break
#Checks if key is already present in dictionary, appends word to list
if first_two in d.keys():
d[first_two].append(line_data)
#If key is not present create a new key and a list for the words.
elif first_two not in d.keys():
list = [line_data]
d[first_two] = list