From 2c5df926729b02736878848e3e020de9e38cbda7 Mon Sep 17 00:00:00 2001 From: Alex Alekseyenko Date: Sun, 20 Jan 2019 20:04:34 -0800 Subject: [PATCH] Fix bug in path_lengths As it's written, path_lengths returns all distances, including the one from the source to itself. --- code/chap03.ipynb | 3 ++- code/chap03soln.ipynb | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/code/chap03.ipynb b/code/chap03.ipynb index 629938ed..2e37f01b 100644 --- a/code/chap03.ipynb +++ b/code/chap03.ipynb @@ -499,7 +499,8 @@ " length_iter = nx.shortest_path_length(G)\n", " for source, dist_map in length_iter:\n", " for dest, dist in dist_map.items():\n", - " yield dist" + " if source != dest:\n", + " yield dist" ] }, { diff --git a/code/chap03soln.ipynb b/code/chap03soln.ipynb index 348e3d85..5f8dd382 100644 --- a/code/chap03soln.ipynb +++ b/code/chap03soln.ipynb @@ -643,7 +643,8 @@ " length_iter = nx.shortest_path_length(G)\n", " for source, dist_map in length_iter:\n", " for dest, dist in dist_map.items():\n", - " yield dist" + " if source != dest:\n", + " yield dist" ] }, { @@ -678,7 +679,7 @@ { "data": { "text/plain": [ - "0.9" + "1.0" ] }, "execution_count": 24,