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, x, lo=0, hi=None, *, key=None)
| 51 | |
| 52 | |
| 53 | def insort_left(a, x, lo=0, hi=None, *, key=None): |
| 54 | """Insert item x in list a, and keep it sorted assuming a is sorted. |
| 55 | |
| 56 | If x is already in a, insert it to the left of the leftmost x. |
| 57 | |
| 58 | Optional args lo (default 0) and hi (default len(a)) bound the |
| 59 | slice of a to be searched. |
| 60 | """ |
| 61 | |
| 62 | if key is None: |
| 63 | lo = bisect_left(a, x, lo, hi) |
| 64 | else: |
| 65 | lo = bisect_left(a, key(x), lo, hi, key=key) |
| 66 | a.insert(lo, x) |
| 67 | |
| 68 | def bisect_left(a, x, lo=0, hi=None, *, key=None): |
| 69 | """Return the index where to insert item x in list a, assuming a is sorted. |
nothing calls this directly
no test coverage detected