【发布时间】:2014-11-27 18:41:46
【问题描述】:
我有一个带标签的文本,我想制作一个包含令牌和文本标签的字典。 我试过这个
text = "he/s is/v a/p good/j man/n"
dic = {}
for w in text.split():
ti = w.split('/')
tok =ti[0]
tag =ti[1]
dic[tok] = tag
print dic
这是输出
{'he': 's'}
{'is': 'v', 'he': 's'}
{'a': 'p', 'is': 'v', 'he': 's'}
{'a': 'p', 'is': 'v', 'good': 'j', 'he': 's'}
{'a': 'p', 'is': 'v', 'good': 'j', 'man': 'n', 'he': 's'}
如何防止重复
【问题讨论】:
标签: python python-2.7 python-3.x dictionary