Last active
March 14, 2018 15:41
-
-
Save amrit3701/fc8ef12b9f15e99dd8a84e7276b1e1c5 to your computer and use it in GitHub Desktop.
Convert Mahankosh.txt to dictionary format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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