-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_code
More file actions
65 lines (41 loc) · 1.16 KB
/
py_code
File metadata and controls
65 lines (41 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import json
dictPoets = {}
engPoets = open("rekhta_poets_english.tsv","r")
for poet in engPoets:
poetInfo = poet.split("\t")
name = poetInfo[0].strip()
link = poetInfo[1].strip()
dictPoets[link] = { "english" : name }
engPoets.close()
# In[2]:
hindiPoets = open("rekhta_poets_hindi.tsv","r",encoding="utf8") #used utf8 encoding - charmap issue
for poet in hindiPoets:
poetInfo = poet.split("\t")
name = poetInfo[0].strip()
link = poetInfo[1].strip().split("?")[0]
poetObj = dictPoets.get(link)
if poetObj == None:
dictPoets[link]={"hindi":name}
else:
poetObj["hindi"]=name
hindiPoets.close()
# In[3]:
urduPoets = open("rekhta_poets_urdu.tsv","r",encoding="utf8")
for poet in urduPoets:
poetInfo = poet.split("\t")
name = poetInfo[0].strip()
link = poetInfo[1].strip().split("?")[0]
poetObj = dictPoets.get(link)
if poetObj == None:
dictPoets[link]={"urdu":name}
else:
poetObj["urdu"]=name
urduPoets.close()
# In[4]:
print(dictPoets)
# In[5]:
with open('poetsDictionary.json', 'w') as fp:
json.dump(dictPoets, fp)