]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-145269: simplify bisect.bisect doc example (GH-145270) (#145367)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 28 Feb 2026 19:28:14 +0000 (20:28 +0100)
committerGitHub <noreply@github.com>
Sat, 28 Feb 2026 19:28:14 +0000 (19:28 +0000)
gh-145269: simplify bisect.bisect doc example (GH-145270)

---------
(cherry picked from commit fdb4b3527f356a84bc00ca32516181016400e567)

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Doc/library/bisect.rst
Lib/test/test_bisect.py

index 3efa3999171646953a8699be3683581902e59274..ecc8d69a2b39ca9d68e706f935264f2ed2ae43d6 100644 (file)
@@ -203,9 +203,9 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco
 based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
 a 'B', and so on::
 
-   >>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
-   ...     i = bisect(breakpoints, score)
-   ...     return grades[i]
+   >>> def grade(score)
+   ...     i = bisect([60, 70, 80, 90], score)
+   ...     return "FDCBA"[i]
    ...
    >>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
    ['F', 'A', 'C', 'C', 'B', 'A', 'A']
index 97204d4cad3871690c0a1d254c562d90c7d46c89..a7e1f533ff2adc1cbe5c515a00a5b3583f8bc916 100644 (file)
@@ -391,9 +391,9 @@ class TestErrorHandlingC(TestErrorHandling, unittest.TestCase):
 
 class TestDocExample:
     def test_grades(self):
-        def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
-            i = self.module.bisect(breakpoints, score)
-            return grades[i]
+        def grade(score):
+            i = self.module.bisect([60, 70, 80, 90], score)
+            return "FDCBA"[i]
 
         result = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
         self.assertEqual(result, ['F', 'A', 'C', 'C', 'B', 'A', 'A'])