im suggesting that this is for some form of mapping:
from itertools import chain def makeMap(d): nodes = set([x for x in chain.from_iterable(d.values())]) return dict([[x, [y for y in d.keys() if x in d[y]]] for x in nodes ])
this code will do it for you :)
EDIT:
and heres (massive) one liner, I would not recommend putting this in code, though, since it is unreadable.
def makeMap(d): return dict([[x, [y for y in d.keys() if x in d[y]]] for x in set([x for x in chain.from_iterable(d.values())]) ])
Steps:
1. make a set of all possible node values ββ2. Find all node values ββin dictionary values, if you put the key that he found in the matching list.
source share