]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145269: simplify bisect.bisect doc example (#145270)
authorNathan Goldbaum <nathan.goldbaum@gmail.com>
Sat, 28 Feb 2026 09:09:39 +0000 (02:09 -0700)
committerGitHub <noreply@github.com>
Sat, 28 Feb 2026 09:09:39 +0000 (09:09 +0000)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
---------

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

index 7f75e85a7eb64173786c253583f9eca40e6afcec..2c29a5ec992737e55d7f19262219289535933cae 100644 (file)
@@ -200,9 +200,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'])