I have a list of list. I am trying to convert it to a dictionary with the key being the n-element of the sublist and the value the first element of the list. I was able to achieve the expected results using loop but I am looking for a more elegant way to write it, using list comprehension for example
array = [
[1, 2, 3],
[5, 4, 8]
]
out = {}
for x in array:
y = x[0]
z = x[1:]
for k in z:
out[k] = y
Result:
out = {
2 : 1,
3 : 1,
4 : 5,
8 : 5
}