Callback in Python igraph Traversal Algorithms

Is it not possible to specify a callback for BFS/DFS in igraph via the Python API? If not, is this not a feature on purpose? I am wondering why R seems to have more functionality than Python with respect to igraph features.

Callbacks aren’t idiomatic Python so the Python interface provides Graph.bfsiter() and Graph.dfsiter() instead, both of which probably allow you to achieve the same thing using a for loop. E.g., something like:

g = Graph.GRG(100, 0.2)
for vertex, dist, parent in g.dfsiter(0, advanced=True):
    if parent is None:
        print(f"DFS traversal starts at vertex {vertex.index}")
        print(f"Vertex {vertex.index} reached at distance {dist} from vertex {parent.index}")
1 Like