How to convert List data type into Dictionary data in python -
i want list converted dictionary e.g
list1=["indrajit","mayur","swapnali","akankasha"]
into dictionary having automatically generated keys like
dict1 = {"1" : "indrajit","2" : "mayur", "3" : "swapnali", "4" : "akankasha"}
you use enumerate
starting @ 1 , convert index string, in dictionary comprehension:
list1=["indrajit","mayur","swapnali","akankasha"] dict1 = {str(k):v k,v in enumerate(list1,1)} print(dict1)
result:
{'1': 'indrajit', '4': 'akankasha', '2': 'mayur', '3': 'swapnali'}
Comments
Post a Comment