I have a list and I’d like that each item of the list becomes the value of a key that doesn’t exist yet but should be created.
This is the list:
['King', 'President', 'VP', ' 2nd VP', '3rd VP']
The desired output must be like this:
[{'title':'King'}, {'title':'President'}, {'title':'VP'}, {'title':'2nd VP'}, {'title':'3rd VP'}]
Thanks for your support
>Solution :
You can do that using List Comprehension
lst = ['King', 'President', 'VP', ' 2nd VP', '3rd VP']
d_lst = [{'title': v} for v in lst]
d_lst = [{'title': 'King'}, {'title': 'President'}, {'title': 'VP'}, {'title': ' 2nd VP'}, {'title': '3rd VP'}]