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

Function insort_right

Lib/bisect.py:4–18  ·  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 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)

Source from the content-addressed store, hash-verified

2
3
4def 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
21def bisect_right(a, x, lo=0, hi=None, *, key=None):

Callers

nothing calls this directly

Calls 2

bisect_rightFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…