graph
Builtin index · Collections & strings
result = graph([directed=false])
Input: directed · Output: result
What it is
Optional named directed (bool, default false).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = graph([directed=false]) | directed bool, optional (default false)not documented yet | result — | Returns a graph handle: a new, empty node+edge graph. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
g = graph()
g.add_edge("A", "B", weight=4)
g.add_edge("A", "C", weight=1)
g.add_edge("C", "B", weight=2)
g.add_edge("B", "D", weight=5)
g.add_edge("C", "D", weight=8)
print(g.shortest_path("A", "D")) # 8, via A -> C -> B -> D (1 + 2 + 5)
output
8
from collections-strings
h = graph()
add_node(h, "X") # an isolated node, no edges yet
h.add_edge("X", "Y")
print(has_edge(h, "X", "Y")) # true
print(has_edge(h, "X", "Z")) # false -- Z isn't even a node
print(neighbors(h, "X")) # ("Y")
output
true
false
("Y")from collections-strings
How it works
graph([directed=]) (§ data structures pass, 2026-09-01, algorithm, Dijkstra's shortest_path; see that module's own doc comment for the node-id normalization rule and why Dijkstra over plain BFS.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.