Skip to content

Instantly share code, notes, and snippets.

@amrit3701
Last active March 14, 2018 15:41
Show Gist options
  • Select an option

  • Save amrit3701/fc8ef12b9f15e99dd8a84e7276b1e1c5 to your computer and use it in GitHub Desktop.

Select an option

Save amrit3701/fc8ef12b9f15e99dd8a84e7276b1e1c5 to your computer and use it in GitHub Desktop.
Convert Mahankosh.txt to dictionary format.
"""Translate Manhankosh.txt to dictionary."""
# Download mahankosh_data.txt: https://drive.google.com/file/d/19nF3Z6OfdDLw2V3CoQ3KOVx7tm-UjYcN/view
with open('mahankosh_data.txt') as f:
data = f.readlines()
mahankosh_dic = convert_to_dict(data)
def convert_to_dict(data):
"""Get Mahankosh data in dictionary format."""
dic = {}
for line in data:
split = line.split(': ')
if len(split) != 1:
dic[split[0]] = split[1]
key = split[0]
else:
if line == '\n':
continue
key_result = dic[key]
key_result += line
dic[key] = key_result
return dic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment