@@ -24,6 +24,8 @@ method to determine whether a value has been found. Instead, the
24
24
functions only call the :meth: `__lt__ ` method and will return an insertion
25
25
point between values in an array.
26
26
27
+ .. _bisect functions :
28
+
27
29
The following functions are provided:
28
30
29
31
@@ -55,7 +57,7 @@ The following functions are provided:
55
57
.. function :: bisect_right(a, x, lo=0, hi=len(a), *, key=None)
56
58
bisect(a, x, lo=0, hi=len(a), *, key=None)
57
59
58
- Similar to :func: `bisect_left `, but returns an insertion point which comes
60
+ Similar to :py: func: `~bisect. bisect_left `, but returns an insertion point which comes
59
61
after (to the right of) any existing entries of *x * in *a *.
60
62
61
63
The returned insertion point *ip * partitions the array *a * into two slices
@@ -70,7 +72,7 @@ The following functions are provided:
70
72
71
73
Insert *x * in *a * in sorted order.
72
74
73
- This function first runs :func: `bisect_left ` to locate an insertion point.
75
+ This function first runs :py: func: `~bisect. bisect_left ` to locate an insertion point.
74
76
Next, it runs the :meth: `insert ` method on *a * to insert *x * at the
75
77
appropriate position to maintain sort order.
76
78
@@ -87,10 +89,10 @@ The following functions are provided:
87
89
.. function :: insort_right(a, x, lo=0, hi=len(a), *, key=None)
88
90
insort(a, x, lo=0, hi=len(a), *, key=None)
89
91
90
- Similar to :func: `insort_left `, but inserting *x * in *a * after any existing
92
+ Similar to :py: func: `~bisect. insort_left `, but inserting *x * in *a * after any existing
91
93
entries of *x *.
92
94
93
- This function first runs :func: `bisect_right ` to locate an insertion point.
95
+ This function first runs :py: func: `~bisect. bisect_right ` to locate an insertion point.
94
96
Next, it runs the :meth: `insert ` method on *a * to insert *x * at the
95
97
appropriate position to maintain sort order.
96
98
@@ -120,7 +122,7 @@ thoughts in mind:
120
122
they are used. Consequently, if the search functions are used in a loop,
121
123
the key function may be called again and again on the same array elements.
122
124
If the key function isn't fast, consider wrapping it with
123
- :func: `functools.cache ` to avoid duplicate computations. Alternatively,
125
+ :py: func: `functools.cache ` to avoid duplicate computations. Alternatively,
124
126
consider searching an array of precomputed keys to locate the insertion
125
127
point (as shown in the examples section below).
126
128
@@ -140,7 +142,7 @@ thoughts in mind:
140
142
Searching Sorted Lists
141
143
----------------------
142
144
143
- The above :func: `bisect ` functions are useful for finding insertion points but
145
+ The above `bisect functions `_ are useful for finding insertion points but
144
146
can be tricky or awkward to use for common searching tasks. The following five
145
147
functions show how to transform them into the standard lookups for sorted
146
148
lists::
@@ -186,8 +188,8 @@ Examples
186
188
187
189
.. _bisect-example :
188
190
189
- The :func: `bisect ` function can be useful for numeric table lookups. This
190
- example uses :func: `bisect ` to look up a letter grade for an exam score (say)
191
+ The :py: func: `~bisect. bisect ` function can be useful for numeric table lookups. This
192
+ example uses :py: func: `~bisect. bisect ` to look up a letter grade for an exam score (say)
191
193
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
192
194
a 'B', and so on::
193
195
@@ -198,8 +200,8 @@ a 'B', and so on::
198
200
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
199
201
['F', 'A', 'C', 'C', 'B', 'A', 'A']
200
202
201
- The :func: `bisect ` and :func: `insort ` functions also work with lists of
202
- tuples. The *key * argument can serve to extract the field used for ordering
203
+ The :py: func: `~ bisect.bisect ` and :py: func: `~bisect. insort ` functions also work with
204
+ lists of tuples. The *key * argument can serve to extract the field used for ordering
203
205
records in a table::
204
206
205
207
>>> from collections import namedtuple
0 commit comments