Skip to content

Conversation

@alexalekseyenko
Copy link

As it's written, path_lengths returns all distances, including the one from the source to itself. Assuming that shouldn't be the case, as the solutions indicate the average path length should be 1.

As it's written, path_lengths returns all distances, including the
one from the source to itself.
@alexalekseyenko
Copy link
Author

If it isn't too unreadable, probably better to do it this way(?):

def path_lengths(G):
    length_iter = nx.shortest_path_length(G)
    for source, dist_map in length_iter:
        for dest in set(dist_map.keys()).difference([source]):
            yield dist_map[dest]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant