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
Post a Comment