Skip to content

Instantly share code, notes, and snippets.

@alces
Created April 4, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/b201af797fb4b70cd8d65665616b1d90 to your computer and use it in GitHub Desktop.
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)
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