S.Bussandri S.Bussandri - 8 months ago 45
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:]}


{1: [2, 3, 4, 5]}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download