-12

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?

2 Answers2

3

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]}
Ajax1234
  • 69,937
  • 8
  • 61
  • 102
0
List = [1,2,3,4,5]

Dict = {List.pop(0):List}

output:

{1: [2, 3, 4, 5]}
THAVASI.T
  • 131
  • 1
  • 5