Skip to content

Commit c466f98

Browse files
committed
Fix to Chapter 3 solution: stats.py, us_population_stats_figure_2.png
chapter3/solutions/us_population_stats_figure_2.png is not correct because the population growth list is unintentionally sorted by `median()` in stats.py. This commit replaces `numbers.sort()` in `median()` with `sorted(numbers)`, which does not modify the list itself but returns a new sorted list, and fixes us_population_stats_figure_2.png. Before this commit: >>> data = [3, 2, 1] >>> median(data) >>> print(data) #=> [1, 2, 3] (data is sorted.) After this commit: >>> data = [3, 2, 1] >>> median(data) >>> print(data) #=> [3, 2, 1] (data is not sorted.)
1 parent e54a046 commit c466f98

File tree

2 files changed

+1
-1
lines changed

2 files changed

+1
-1
lines changed

chapter3/solutions/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def median(numbers):
1818
N = len(numbers)
1919

2020
# sort the list in ascending order
21-
numbers.sort()
21+
numbers = sorted(numbers)
2222

2323
# find the median
2424
if N % 2 == 0:
-15.7 KB
Loading

0 commit comments

Comments
 (0)