S.Bussandri S.Bussandri - 1 month ago 6
Python Question

Turning a list into a dictionary?

Im trying to turn a list into a dictionary. so say i have a list like:

list = [1,2,3,4,5]


and i want my dictionary to be:

dict = {1:2,3,4,5}


is there anyway to do this?

Answer Source

I believe you want a dictionary with a single key and a list:

l = [1,2,3,4,5]

d = {l[0]:l[1:]}

Output:

{1: [2, 3, 4, 5]}