['key=IAfpK', ' age=58', ' key=WNVdi', ' age=64', ' key=jp9zt', ' age=47', ' key=0Sr4C', ' age=68', ' key=CGEqo', ' age=76', ' key=IxKVQ', ' age=79', ' key=eD221', ' age=29']
I got the following list, i need to convert it to a dictionary,like
{"IAfpK":58,"WNVdi":,"64":,.....}
I have tried ast library and JSON.loads but in vain
>Solution :
Simple one-liner using a dict comprehension:
{x.split("=")[1]: int(y.split("=")[1]) for x,y in zip(arr[::2],arr[1::2])}
zip(arr[::2],arr[1::2]) iterates over pairs of the array, and str.split extracts the correct value for the key and value.