I am trying to solve the following problem using dict and list comprehension. Given
input = {"a":["b","c"], "d":["b","e"], "f":["g","c"]}
expected output is ::
output = {"b":["a","d"], "c":["a","f"], "e":["d"], "g":["f"]}
So far, I have only been able to come up with ::
output = {}
for (k,v) in input.items():
for x in v:
if x[0] not in output:
output[x[0]] = [k]
else:
output[x[0]].append(k)
What would be a possible one line dict+list comprehension method to do this?