DEV Community

loading...

Discussion on: Dijkstra's algorithm in python: algorithms for beginners

Collapse
nataliaalshevskaya profile image
Natalia Alshevskaya

This next could be written little bit shorter:

path, current_vertex = deque(), dest
while previous_vertices[current_vertex] is not None:
path.appendleft(current_vertex)
current_vertex = previous_vertices[current_vertex]
if path:
path.appendleft(current_vertex)

----->>>

path, current_vertex = deque(), dest
while current_vertex:
path.appendleft(current_vertex)
current_vertex = previous_vertices[current_vertex]

Forem Open with the Forem app