how can i make a square matrix from a nested dict?

I just did a walkaround with a list.

dis = dict(nx.all_pairs_shortest_path_length(graph))

Nations = list(dis.keys())
master = [[""]]

for x in Nations:
    master[0].append(x)

for Nat1 in dis:
    master.append([Nat1])
    for Nat2 in Nations:
        master[-1].append(dis[Nat1][Nat2])

Thanks for everyone taking care of this problem. Have a wonderful day!

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top