Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the left of the leftmost 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 or
(a, x, lo=0, hi=None, *, key=None)
| 55 | |
| 56 | |
| 57 | def insort_left(a, x, lo=0, hi=None, *, key=None): |
| 58 | """Insert item x in list a, and keep it sorted assuming a is sorted. |
| 59 | |
| 60 | If x is already in a, insert it to the left of the leftmost x. |
| 61 | |
| 62 | Optional args lo (default 0) and hi (default len(a)) bound the |
| 63 | slice of a to be searched. |
| 64 | |
| 65 | A custom key function can be supplied to customize the sort order. |
| 66 | """ |
| 67 | |
| 68 | if key is None: |
| 69 | lo = bisect_left(a, x, lo, hi) |
| 70 | else: |
| 71 | lo = bisect_left(a, key(x), lo, hi, key=key) |
| 72 | a.insert(lo, x) |
| 73 | |
| 74 | def bisect_left(a, x, lo=0, hi=None, *, key=None): |
| 75 | """Return the index where to insert item x in list a, assuming a is sorted. |
nothing calls this directly
no test coverage detected
searching dependent graphs…