Last active
July 6, 2020 07:08
-
-
Save jonathanagustin/e47359472bb95ae373004c114cc1257b to your computer and use it in GitHub Desktop.
Python - build graph with list of edges
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
| def buildGraph(edges): | |
| from collections import defaultdict | |
| graph = defaultdict(list) | |
| for u, v in edges: | |
| graph[u].append(v) | |
| graph[v].append(u) # delete this line if directed graph |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment