Just as a side note, you can do this quite simply by using the enumerate
and zip
functions.
lst = [[3, 0, 7, 4, 5], [2, 3, 0, 1, 2], [6, 6, 7, 6, 6]]
d = dict(enumerate(zip(*lst)))
zip(*lst)
is basically a transpose function. It returns a list in Python 2, or azip
object in Python 3, which can be converted into the equivalent list.[(3, 2, 6), (0, 3, 6), (7, 0, 7), (4, 1, 6), (5, 2, 6)]
enumerate()
basically just tacks the index of an element before it, and returns anenumerate
object, which when converted into a list returns a list of tuples.[(0, (3, 2, 6)), (1, (0, 3, 6)), (2, (7, 0, 7)), (3, (4, 1, 6)), (4, (5, 2, 6))]
dict()
takes a list of tuples and turns them into key/value pairs.{0: (3, 2, 6), 1: (0, 3, 6), 2: (7, 0, 7), 3: (4, 1, 6), 4: (5, 2, 6)}