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

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -