I am trying to print all possible paths using Floyd-Warshall algorithm and networkx (Python). The thing is, I don't know how to do it properly (readable, as a list). I have these paths from my graph:
X = nx.floyd_warshall(gra)
Y = {a: dict(b) for a, b in X.items()}
print(Y)
and it returns this:
{(0, 0): {(0, 0): 0, (1, 0): 1, (0, 1): 1, (1, 1): 2, (0, 2): 2, (1, 2): 3}, (1, 0): {(1, 0): 0, (0, 0): 1, (1, 1): 1, (0, 1): 2, (0, 2): 3, (1, 2): 2}, (0, 1): {(0, 1): 0, (0, 0): 1, (1, 1): 1, (0, 2): 1, (1, 0): 2, (1, 2): 2}, (1, 1): {(1, 1): 0, (1, 0): 1, (0, 1): 1, (1, 2): 1, (0, 0): 2, (0, 2): 2}, (0, 2): {(0, 2): 0, (0, 1): 1, (1, 2): 1, (0, 0): 2, (1, 0): 3, (1, 1): 2}, (1, 2): {(1, 2): 0, (1, 1): 1, (0, 2): 1, (0, 0): 3, (1, 0): 2, (0, 1): 2}}
How can I convert it in a more readable format? For example, is it possible to print all possible paths one by one? I would like an output like this:
[(0, 0), (1, 0)]
[(1, 0), (1, 1)]
[(0, 0), (1, 0), (1, 1)]
...
[(0, 0), (1, 0), (1, 1), (0, 1), (0, 2), (1, 2)]
Alternatively, is it possible to print them as a JSON (or like this):
{(0, 0):
{(0, 0): 0,
(1, 0): 1,
(0, 1): 1,
(1, 1): 2,
(0, 2): 2,
(1, 2): 3},
(1, 0):
{(1, 0): 0,
(0, 0): 1,
(1, 1): 1,
(0, 1): 2,
(0, 2): 3,
(1, 2): 2},
[......]
(0, 1): 2}}
Thanks...