I am looking to convert a list of lists which contains some details in the below format into a dictionary.
[['1234567890', 'abcdef', 'xyzd'],
['0987654321', 'pqrstuvw', 'oiu'],
['6767547879', 'djkaddsd', 'dsad']]
I want it to be in the below format.
{'target0': ['1234567890', 'abcdef', 'xyzd'],
'target1': ['0987654321', 'pqrstuvw', 'oiu'],
'target2': ['6767547879', 'djkaddsd', 'dsad']}
>Solution :
I’d prefer enumerate in a dictionary comprehension:
>>> {f'target{k}': v for k, v in enumerate(lst)}
{'target0': ['1234567890', 'abcdef', 'xyzd'],
'target1': ['0987654321', 'pqrstuvw', 'oiu'],
'target2': ['6767547879', 'djkaddsd', 'dsad']}
>>>
Also I used f-strings.