@@ -0,0 +1,2263 @@
+from collections import defaultdict, deque%0A%0A%0Aclass Graph(object):%0A    def __init__(self):%0A        self.nodes = set()%0A        self.edges = defaultdict(list)%0A        self.distances = %7B%7D%0A%0A    def add_node(self, value):%0A        self.nodes.add(value)%0A%0A    def add_edge(self, from_node, to_node, distance):%0A        self.edges%5Bfrom_node%5D.append(to_node)%0A        self.edges%5Bto_node%5D.append(from_node)%0A        self.distances%5B(from_node, to_node)%5D = distance%0A%0A%0Adef dijkstra(graph, initial):%0A    #visited array initalized to 0%0A    visited = %7Binitial: 0%7D%0A    path = %7B%7D%0A%0A    nodes = set(graph.nodes)%0A    #while nodes is not empty%0A    while nodes:%0A        min_node = None%0A        for node in nodes:%0A            if node in visited:%0A                if min_node is None:%0A                    min_node = node%0A                #finding min nodes in nodes%0A                elif visited%5Bnode%5D %3C visited%5Bmin_node%5D:%0A                    min_node = node%0A        if min_node is None:%0A            break%0A        #take min node from node and check %0A        nodes.remove(min_node)%0A        current_weight = visited%5Bmin_node%5D%0A        #if new distance less than already computed distance then update it%0A        for edge in graph.edges%5Bmin_node%5D:%0A            try:%0A                weight = current_weight + graph.distances%5B(min_node, edge)%5D%0A            except:%0A                continue%0A            if edge not in visited or weight %3C visited%5Bedge%5D:%0A                visited%5Bedge%5D = weight%0A                path%5Bedge%5D = min_node%0A%0A    return visited, path%0A%0A#function to find the shortest path from source to destination%0Adef shortest_path(graph, origin, destination):%0A    visited, paths = dijkstra(graph, origin)%0A    full_path = deque()%0A    _destination = paths%5Bdestination%5D%0A%0A    while _destination != origin:%0A        full_path.appendleft(_destination)%0A        _destination = paths%5B_destination%5D%0A%0A    full_path.appendleft(origin)%0A    full_path.append(destination)%0A%0A    return visited%5Bdestination%5D, list(full_path)%0A%0Aif __name__ == '__main__':%0A    graph = Graph()%0A%0A    for node in %5B'A', 'B', 'C', 'D'%5D:%0A        graph.add_node(node)%0A%0A    graph.add_edge('A', 'B', 10)%0A    graph.add_edge('A', 'C', 20)%0A    graph.add_edge('B', 'D', 15)%0A    graph.add_edge('C', 'D', 30)%0A%0A    print(shortest_path(graph, 'A', 'D')) %0A

Create dijkstra.py