If I have two List of tuples
tuple2list=[(4, 21), (5, 10), (3, 8), (6, 7)]
tuple3list=[(4, 180, 21), (5, 90, 10), (3, 270, 8), (6, 0, 7)]
How do I convert it to a dictionary as below,
tuple2list2dict={4:21, 5:10, 3:8, 6:7}
tuple3list2dict={4: {180:21}, 5:{90:10}, 3:{270:8}, 6:{0:7}}
I know how to do it for 2 elements in tuples, using,
tuple2list2dict=dict((x[0], index) for index,x in enumerate(tuple2list))
But for 3 elements I have problem, have error trying the below,
tuple3list2dict=dict((x[0], dict(x[1], index)) for index,x in enumerate(tuple3list))
How do I reuse the above code for 3 element tuple to create a dictionary?
Any pointer appreciated or point me where I could read more on this. Have trouble finding it in the internet.