Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the right of the rightmost x. Optional args lo (default 0) and hi (default len(a)) bound the slice of a to be searched. A custom key function can be supplied to customize the sort
(a, x, lo=0, hi=None, *, key=None)
| 2 | |
| 3 | |
| 4 | def insort_right(a, x, lo=0, hi=None, *, key=None): |
| 5 | """Insert item x in list a, and keep it sorted assuming a is sorted. |
| 6 | |
| 7 | If x is already in a, insert it to the right of the rightmost x. |
| 8 | |
| 9 | Optional args lo (default 0) and hi (default len(a)) bound the |
| 10 | slice of a to be searched. |
| 11 | |
| 12 | A custom key function can be supplied to customize the sort order. |
| 13 | """ |
| 14 | if key is None: |
| 15 | lo = bisect_right(a, x, lo, hi) |
| 16 | else: |
| 17 | lo = bisect_right(a, key(x), lo, hi, key=key) |
| 18 | a.insert(lo, x) |
| 19 | |
| 20 | |
| 21 | def bisect_right(a, x, lo=0, hi=None, *, key=None): |
nothing calls this directly
no test coverage detected
searching dependent graphs…