For standard response purposes, I need to convert a string from this:
[(('Ethyl', 'alcohol'), 1.0), (('clean', 'water'), 1.0)]
to this:
[{"words": "Ethyl,alcohol", "score": 1.0}, {"words": "clean,water", "score": 1.0}]
I was able to code it correctly but my code doesn't seems like "pythony".. Here is my code:
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)
Is my code acceptable? I will be dealing with this more often and would like to see a more readable way the python way.