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

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -