我有这个python集:
>>> print (x)
[(0, Synset('basic.n.01'), Synset('cry.v.02')),
(3, Synset('base.n.01'), Synset('help.v.04'))]
我想将它解析为列表或字典,如下所示:
{"value": 0, "keyword1": "basic", "keyword2": "cry"}
{"value": 3, "keyword1": "base", "keyword2": "help"}
答案 0 :(得分:1)
您可以将数据结构转换为字典,但需要辅助功能:
def prepare(item):
return item[0],item[1].lemma_names()[0], item[2].lemma_names()[0]
keys = "value", "keyword1", "keyword2"
[dict(zip(keys, prepare(item))) for item in x]