Skip to content

Commit

Permalink
Merge pull request #19 from parikshit14/forth-task
Browse files Browse the repository at this point in the history
completed task forth
  • Loading branch information
MridulS authored Mar 30, 2022
2 parents 75f38e4 + fb1da0b commit a2dc5c0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 2022-round-1/parikshit14/nx_tutorial_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import networkx as nx
import matplotlib.pyplot as plt

# creating DiGraph object
DG = nx.DiGraph()
DG.add_edges_from([(1, 2), (2, 3)]) # adding node 1,2,3 and connecting them 1->2->3
DG.add_edge("hello", "world") # adding node and connecting them "hello" -> "world"
DG.add_edge("world", (5, 6)) # adding node (5,6) and connecting them "world" -> (5,6)
DG.add_edge(1, (5, 6)) # adding edge 1 -> (5,6)
DG.add_edge(1, "world") # adding edge 1 -> "world"

# Drawing the DiGraph
nx.draw(DG, with_labels=True)

# Calculating the shortest path and printing it
sp = nx.shortest_path(DG)
print(sp)

0 comments on commit a2dc5c0

Please sign in to comment.