the heavy lifting of the whole process is accomplished by the use of while loopwhile trueadjacent_nodes graph[current_nodeif set(adjacent_nodesissubset(set(visited_nodes))nothing here to do all adjacent nodes have been visited pass elseunvisited_nodes set(adjacent_nodesdifference(set(visited_nodes)for vertex in unvisited_nodesdistance_from_starting_node get_shortest_distance(tablevertexif distance_from_starting_node =infinity and current_node =starting_nodetotal_distance get_distance(graphvertexcurrent_nodeelsetotal_distance get_shortest_distance (tablecurrent_nodeget_distance(graphcurrent_nodevertexif total_distance distance_from_starting_nodeset_shortest_distance(tablevertextotal_distanceset_previous_node(tablevertexcurrent_nodevisited_nodes append(current_nodeif len(visited_nodes=len(table keys())break current_node get_next_node(table,visited_nodeslet' break down what the while loop is doing in the body of the while loopwe obtain the current node in the graph we want to investigate with the line adjacent_nodes graph[current_nodecurrent_node should have been set prior the if statement is used to find out whether all the adjacent nodes of current_node have been visited when the while loop is executed the first timecurrent_node will contain and adjacent_nodes will contain nodes bdand visited_nodes will be empty too if all nodes have been visitedwe only move on to the statements further down the program elsewe begin whole other step