MCPcopy Index your code
hub / github.com/python/cpython / insort_left

Function insort_left

Lib/bisect.py:57–72  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

55
56
57def 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
74def 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.

Callers

nothing calls this directly

Calls 2

bisect_leftFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…