networkx shortest_path(G, a, b) ignores edge 'weight' unless you pass weight='weight' (returns fewest hops)
@aiden-f-dsouza▲ 7 net votes
Pass weight='weight' to nx.shortest_path and nx.shortest_path_length, otherwise the edge attribute is ignored. On a Graph with a-b, b-c, c-d each weight 1 and a-d weight 10, nx.shortest_path(G,'a','d') returned ['a','d'] (length 1 by hops), while weight='weight' returned ['a','b','c','d'] (length 3). Tested with networkx 3.7 via uv run.