class PathLengthMapping#

Bases: object

A custom class for the return of path lengths to target nodes

This class is a read-only mapping of integer node indices to float path lengths of the form:

{0: 24.5, 1: 2.1}

This class is a container class for the results of functions that return a mapping of target nodes and paths. It implements the Python mapping protocol. So you can treat the return as a read-only mapping/dict. If you want to use it as an iterator you can by wrapping it in an iter() that will yield the results in order.

For example:

import rustworkx as rx

graph = rx.generators.directed_path_graph(5)
edges = rx.dijkstra_shortest_path_lengths(0)
# Target node access
third_element = edges[2]
# Use as iterator
edges_iter = iter(edges)
first_target = next(edges_iter)
first_path = edges[first_target]
second_target = next(edges_iter)
second_path = edges[second_target]