Created
April 16, 2012 18:16
-
-
Save cammckinnon/2400465 to your computer and use it in GitHub Desktop.
reverse graph
This file contains hidden or 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
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