An interesting python sorting module: bisect

Source: Internet
Author: User
Today, my colleague talked about a Python sort of module bisect, I think it is very interesting to share with you.

First look at the structure of the module:

The first five properties are interesting to be able to play out to see the value, here is not introduced.

First of all, make sure that the list of actions is sorted before using the function of this module.

First look at the Insort function:

The result of its insertion does not affect the original sort.

And look at the Bisect function:

The purpose is to find where the value will be inserted and return it without inserting it.

Then look at the Bisect_left and Bisect_right functions, where the function will insert a repeating number and return where it will be inserted:

The corresponding insertion functions are insort_left and insort_right:

It can be seen that the results of two functions are the same, but the position of inserting is different.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.