Convert list to dict in Python -


how can convert list

my_list = ["a", "b", "c"] 

into dictionary

my_dict = {     1: "a",     2: "b",     3: "c" } 

the keys should indexes + 1 in example.

a simple solution is:

dict(enumerate(my_list, 1)) 

for example:

>>> dict(enumerate(["a", "b", "c"], 1)) {1: 'a', 2: 'b', 3: 'c'} 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -