Skip to content

Commit fdb4b35

Browse files
gh-145269: simplify bisect.bisect doc example (#145270)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> --------- Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
1 parent 09e8c38 commit fdb4b35

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Doc/library/bisect.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco
200200
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
201201
a 'B', and so on::
202202

203-
>>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
204-
... i = bisect(breakpoints, score)
205-
... return grades[i]
203+
>>> def grade(score)
204+
... i = bisect([60, 70, 80, 90], score)
205+
... return "FDCBA"[i]
206206
...
207207
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
208208
['F', 'A', 'C', 'C', 'B', 'A', 'A']

Lib/test/test_bisect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ class TestErrorHandlingC(TestErrorHandling, unittest.TestCase):
391391

392392
class TestDocExample:
393393
def test_grades(self):
394-
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
395-
i = self.module.bisect(breakpoints, score)
396-
return grades[i]
394+
def grade(score):
395+
i = self.module.bisect([60, 70, 80, 90], score)
396+
return "FDCBA"[i]
397397

398398
result = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
399399
self.assertEqual(result, ['F', 'A', 'C', 'C', 'B', 'A', 'A'])

0 commit comments

Comments
 (0)