From f841b96d692092b6768eed3e2f6a47d06f6c79db Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 20 Sep 2019 08:57:18 -0700 Subject: [PATCH 1/2] Put less code in the try block --- Lib/statistics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/statistics.py b/Lib/statistics.py index d81596e5d8abcd..f6e6ef32a62b0d 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -555,8 +555,9 @@ def mode(data): """ data = iter(data) + pairs = Counter(data).most_common(1) try: - return Counter(data).most_common(1)[0][0] + return pairs[0][0] except IndexError: raise StatisticsError('no mode for empty data') from None From fe4f61e3b320c0c8810213f89b44dcd341e82d6c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 20 Sep 2019 10:01:48 -0700 Subject: [PATCH 2/2] Document another property of the default method --- Lib/statistics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/statistics.py b/Lib/statistics.py index f6e6ef32a62b0d..0d747b3d6c0531 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -603,6 +603,7 @@ def multimode(data): # mean=0.300. Only the latter (which corresponds with R6) gives the # desired cut point with 30% of the population falling below that # value, making it comparable to a result from an inv_cdf() function. +# The R6 exclusive method is also idempotent. # For describing population data where the end points are known to # be included in the data, the R7 inclusive method is a reasonable