Skip to content

Commit 4152bbb

Browse files
miss-islingtonngoldbaumeendebakpt
authored
[3.14] gh-145269: simplify bisect.bisect doc example (GH-145270) (#145367)
gh-145269: simplify bisect.bisect doc example (GH-145270) --------- (cherry picked from commit fdb4b35) Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
1 parent fc2a6cf commit 4152bbb

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
@@ -203,9 +203,9 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco
203203
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
204204
a 'B', and so on::
205205

206-
>>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
207-
... i = bisect(breakpoints, score)
208-
... return grades[i]
206+
>>> def grade(score)
207+
... i = bisect([60, 70, 80, 90], score)
208+
... return "FDCBA"[i]
209209
...
210210
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
211211
['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)