class BFSSuccessors#

Bases: object

A custom class for the return from rustworkx.bfs_successors()

The class can is a read-only sequence of tuples of the form:

[(node, [successor_a, successor_b])]

where node, successor_a, and successor_b are the data payloads for the nodes in the graph.

This class is a container class for the results of the rustworkx.bfs_successors() function. It implements the Python sequence protocol. So you can treat the return as read-only sequence/list that is integer indexed. 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)
bfs_succ = rx.bfs_successors(0)
# Index based access
third_element = bfs_succ[2]
# Use as iterator
bfs_iter = iter(bfs_succ)
first_element = next(bfs_iter)
second_element = next(bfs_iter)