Skip to content

Instantly share code, notes, and snippets.

@Mgancita
Created February 13, 2022 21:01
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 Mgancita/c4833d448bc928924710c2e01d16136e to your computer and use it in GitHub Desktop.
Save Mgancita/c4833d448bc928924710c2e01d16136e to your computer and use it in GitHub Desktop.
import networkx as nx
G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.add_edges_from([(1, 2), (2, 3)])
print(nx.shortest_path(G, 1, 3))
# [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment