I have a list of tuples and I want to convert them to dictionary but the key should be tuples index in the list+1
So if my list of tuple is
[(113, 254), (163, 253), (230, 252), (197, 251), (184, 249), (211, 247), (151, 245), (242, 243), (173, 242), (191, 238)]
I want to create a dictionary of the list of tuples having key as tuples index in the list + 1. Similar to
{1:(113, 254), 2:(163, 253), 3:(230, 252), 4:(197, 251), 5:(184, 249), 6:(211,247), 7:(151, 245), 8:(242, 243), 9:(173, 242), 10:(191, 238)}
Advertisement
Answer
>>> x = [(113, 254), (163, 253), (230, 252), (197, 251), (184, 249), (211, 247), (151, 245), (242, 243), (173, 242), (191, 238)] >>> dict(enumerate(x, start=1)) {1: (113, 254), 2: (163, 253), 3: (230, 252), 4: (197, 251), 5: (184, 249), 6: (211, 247), 7: (151, 245), 8: (242, 243), 9: (173, 242), 10: (191, 238)}