MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / insort_left

Function insort_left

tools/python-3.11.9-amd64/Lib/bisect.py:53–66  ·  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, x, lo=0, hi=None, *, key=None)

Source from the content-addressed store, hash-verified

51
52
53def 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
68def 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.

Callers

nothing calls this directly

Calls 2

bisect_leftFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected