I want to create a dictionary out of a given list, in just one line. The keys of the dictionary will be indices, and values will be the elements of the list. Something like this:
a = [51,27,13,56] #given list
d = one-line-statement #one line statement to create dictionary
print(d)
Output:
{0:51, 1:27, 2:13, 3:56}
I don't have any specific requirements as to why I want one line. I'm just exploring python, and wondering if that is possible.
{[x[0]:51, x[1]:27, x[2]:13, x[3]:56}
.zip()
:dict(zip(x, a))
.