出于标准响应的目的,我需要从中转换字符串:
[(('Ethyl', 'alcohol'), 1.0), (('clean', 'water'), 1.0)]
对此:
[{"words": "Ethyl,alcohol", "score": 1.0}, {"words": "clean,water", "score": 1.0}]
我能够正确编码,但我的代码看起来不像“pythony”。这是我的代码:
lst = []
for data in dataList:
dct = {}
dct['words'] = data[0][0] + ',' + data[0][1]
dct['score'] = data[1]
lst.append(dct)
sResult = json.dumps(lst)
print(sResult)
我的代码可以接受吗?我会更频繁地处理这个问题,并希望看到一种更可读的 python 方式。
有只小跳蛙
汪汪一只猫
相关分类