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