Hi,
From below lists written manually, I can make a dictionary ('words' include Persian font):
words = ['آیا', 'او', 'روزی', 'میآید']
heads = [4, 4, 4, 0]
But when I extract the same 2 lists ('words' from the 2nd column, and 'heads' from 15th column) the dictionary is empty! The txt file is like this:
1 آیا آیا ADV ADV _ 4 PART _ _
2 او او PRO PRO _ 4 SBJ _ _
3 روزی روز N N _ 4 NVE _ _
4 میآید آمد#آ V V _ 0 ROOT _ _
And here is my code:
# .*. coding: utf-8 .*.
from __future__ import unicode_literals
from collections import defaultdict
myfile = open('parsed.txt', "r")
raw = myfile.read()
raw = unicode(raw, encoding="utf-8")
lines = raw.splitlines()
col = []
words = []
heads = []
labels = []
rev_heads = defaultdict(list)
for line in lines:
if line.strip():
col = line.split()
key=col[1], value = col[15]
rev_heads[str(key)].append(str(value))
print rev_heads
myfile.colse()
What's wrong with my code?
Thanks for your help.
- Masoud