Hi, i have this output from a SQL query :
new = (('{reason:slash,data:{"SET0":"=SET2"}}',), ('{reason:slash,data:{"""REM_1""": """=0xFF""", """REM_2""": """=0x1""", """SET0:REM_3""": """=SET2:REM_3""", """MREM_4""": """=0xFF"""};{}}',))
I am trying to get it such that i put all these items in a dic in the following manner :
{'MREM_4': '=0xFF', 'REM_2': '=0x1', 'REM_1': '=0xFF', 'SET0:REM_3': '=SET2:REM_3'}
THe way i went about doing this is :
trace={}
for reason in new:
for oper in reason:
data = oper.split(';')
trace.update(eval(data.pop(0).split('data:')[1].split(';')[0]))
>>> print trace
{'MREM_4': '=0xFF', 'REM_2': '=0x1', 'REM_1': '=0xFF', 'SET0:REM_3': '=SET2:REM_3'}
I am wondering if there is a better way to do it without using the pop function, if for eg the data:{'SET0':'SET2'} doesnt appear as the first entry, than the above will break since i will be poping the wrong item. Any suggestion is appreciated, thanks