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

Function bisect_left

Lib/bisect.py:74–107  ·  view source on GitHub ↗

Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.insert(i, x) will insert just before the leftmost x already there. Optional ar

(a, x, lo=0, hi=None, *, key=None)

Source from the content-addressed store, hash-verified

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.
76
77 The return value i is such that all e in a[:i] have e < x, and all e in
78 a[i:] have e >= x. So if x already appears in the list, a.insert(i, x) will
79 insert just before the leftmost x already there.
80
81 Optional args lo (default 0) and hi (default len(a)) bound the
82 slice of a to be searched.
83
84 A custom key function can be supplied to customize the sort order.
85 """
86
87 if lo < 0:
88 raise ValueError('lo must be non-negative')
89 if hi is None:
90 hi = len(a)
91 # Note, the comparison uses "<" to match the
92 # __lt__() logic in list.sort() and in heapq.
93 if key is None:
94 while lo < hi:
95 mid = (lo + hi) // 2
96 if a[mid] < x:
97 lo = mid + 1
98 else:
99 hi = mid
100 else:
101 while lo < hi:
102 mid = (lo + hi) // 2
103 if key(a[mid]) < x:
104 lo = mid + 1
105 else:
106 hi = mid
107 return lo
108
109
110# Overwrite above definitions with a fast C implementation

Callers 5

median_groupedFunction · 0.90
pdfFunction · 0.90
cdfFunction · 0.90
insort_leftFunction · 0.85
test_colorsMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_colorsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…