I want to build a dict in python from a list, the key of the dict is the first column and the value of the map is the second column. Is there any elegant way to implement this?
For example,
A= [[1,2], [1,3], [2,3]]
The result is
M={1:[2,3],2:[3]}
My own way is
for row in A:
if row[0] not in M: M[row[0]] = []
M[row[0]].append(row[1])
Is there any better solution? Functional Programming methods are preferred.