I want to create a dictionary from this list in only one line. The keys for the dictionary will be indexes, and the values โโwill be list items. Something like that:
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 have no specific requirements as to why I want a single line. I am just learning python and wondering if this is possible.
Nawaz May 17 '13 at 11:19 2013-05-17 11:19
source share