Created
April 4, 2018 11:47
-
-
Save alces/b201af797fb4b70cd8d65665616b1d90 to your computer and use it in GitHub Desktop.
Wrest a dictionary of lists (e.g., turn a dict of nodes as keys and lists of groups as values into a dict of groups as keys and lists of nodes as values)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrest_dict(orig): | |
pairs = [(g, n) for n in orig.keys() for g in orig[n]] | |
nodes4group = lamdba g: sorted(n[1] for n in pairs if n[0] == g) | |
return {g[0]: nodes4group(g[0]) for g in pairs} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment