Python sorting and python dictionary sorting

Source: Internet
Author: User

Python sorting and python dictionary sorting
[TOC] # stability and significance of the Sorting Algorithm in the sequence to be sorted, there are records with the same keywords, the relative order of these records remains unchanged after sorting, the sorting algorithm is stable. The sorting of multiple keywords cannot be completed due to unstable sorting. For example, in integer sorting, the higher the number's priority, the higher the order from the high to the low number of digits. Then the sorting of each bit requires a stable algorithm. Otherwise, the correct result cannot be obtained. That is, ** to sort multiple keywords multiple times, you must use a stable algorithm ** # bubble sort ''' python! [Screen Shot at 10.23.12 A] (media/14970829036232/second) defdef bubble_sort (alist): "" Bubble Sorting "if len (alist) <= 1: return alistfor j in range (len (alist)-1,0,-1): for I in range (j): if alist [I]> alist [I + 1]: alist [I], alist [I + 1] = alist [I + 1], alist [I] return alist ''' ### time complexity * optimal time complexity: O (n) traversal does not find any elements that can be exchanged. Sort sleep * worst time complexity: $ O (n ^ 2) $ * Stability: stable ## select sort # insert sort

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.