Python is an interesting module, bisect, it feels interesting, how interesting, below to give you the word.
Our husband becomes a list
data=[4,8,7,1]data.sort ()
Print this list
[1,4,7,8]
Import bisect
Import Bisect
Inserting data
Bisect.insort (data,3)
Print data
[1, 3, 4, 7, 8]
Visible after inserting does not break the original list sort
Let's use the collar function again.
Print (Bisect.bisect (data,2))
Printing 1
Here is the location where the print is inserted. But it's not really plugged in.
The Bisect_left and Bisect_right functions, which are used to insert duplicate values, return where they will be inserted
Print (Bisect.bisect_left (data,2)) Print (Bisect.bisect_right (data,2))
Results:
11
is not inserted, but
Insort_left and Insort_right are plugged in.
Bisect.insort_right (data,2) bisect.insort_left (data,2)
Execution results
[1, 2, 2, 4, 7, 8]
As a result, insertions are not the same.
Open Source Address: https://github.com/liwanlei/
contact me: qq:952943386 email:[email protected] QQ Group: 194704520 new Group: 683894834
The bisect of the Python module