lst = [['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]]
dct = {l[0]: list(l[1:]) for l in zip(*lst)}
# {'a': [1, 4], 'b': [2, 5], 'c': [3, 6]}
This makes use of zip()
and the unpacking operator *
to "rotate" the list lst
(turn it into [['a', 1, 4], ['b', 2, 5], ['c', 3, 6]]
). This is a fairly common idiom.
Then we just iterate over each of those sublists in a dict comprehension, assign the zeroth element as the key, and the rest of the elements as the value.
Note that by default zip()
returns tuples instead of lists, so we have to typecast l[1:]
to a list
if we want to be able to modify it later. This may not be necessary in your use case.