I have a dictionary.txt file represented as {{key: value}}. I built a dictionary translation web so I wanted to initialize a variable whose data dictionary type is in python for storing. I use the django framework to process. Here is my dictionary reader.
def read_dictionary(fileName):
dict = {}
my_dict = {}
with open(fileName, 'r', encoding="utf8") as f:
for line in f:
items = line.split(':')
key, values = items[0].replace('X', '*'), items[1].strip().replace('\n', '')
dict[key] = values
for k, v in dict.items():
my_dict.setdefault(v, []).append(k)
return my_dict
How can I initialize variable my_dict = value from dictionary file and I can it in myapp folder ? Thank you. Do I need to create a model object and save it under the database?