[Python-checkins] Minor code and comment cleanup (GH-16315) (GH-16316)

Raymond Hettinger webhook-mailer at python.org
Sat Sep 21 01:18:14 EDT 2019


https://github.com/python/cpython/commit/8fe4755aa3a3ef21d1cc90c5e393c7b13b89f9f9
commit: 8fe4755aa3a3ef21d1cc90c5e393c7b13b89f9f9
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-09-20T22:18:10-07:00
summary:

Minor code and comment cleanup (GH-16315) (GH-16316)

(cherry picked from commit 7ce4bfa8cfcc78d03e164f2de64a2caad1d919af)

Co-authored-by: Raymond Hettinger <rhettinger at users.noreply.github.com>

files:
M Lib/statistics.py

diff --git a/Lib/statistics.py b/Lib/statistics.py
index d81596e5d8ab..0d747b3d6c05 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
 
@@ -602,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



More information about the Python-checkins mailing list