Skip to content

Instantly share code, notes, and snippets.

@cammckinnon
Created April 16, 2012 18:16
Show Gist options
  • Save cammckinnon/2400465 to your computer and use it in GitHub Desktop.
Save cammckinnon/2400465 to your computer and use it in GitHub Desktop.
reverse graph
from collections import defaultdict
def reverseGraph(Graph):
newGraph = defaultdict(lambda: [0])
for left in Graph:
leftsNeighbors = Graph[left][1:]
for right in leftsNeighbors:
newGraph[right].append(left)
return newGraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment