Select and sort in Python, and sort in python
Select sort:
Selection sort is a simple and intuitive sorting algorithm. It works as follows. First, find the smallest (large) element in the unordered sequence, store it to the starting position of the sorting sequence, and then continue searching for the smallest (large) element from the remaining unordered elements, put it at the end of the sorted sequence. And so on until all elements are sorted. The main advantages of sorting are related to data movement. If an element is in the correct final position, it will not be moved. When sorting is selected, an element is exchanged each time. At least one of them will be moved to its final position. Therefore, a maximum of N-1 exchanges can be performed on tables with n elements. In all sorting methods that rely entirely on swapping to move elements, selecting sorting is a good one.
Python implementation:
# Selection_sort.py def selection_sort (arr): count = len (arr) for I in range (count-1 ): # swap n-1 min = I # Find the smallest number for j in range (I, count): if arr [min]> arr [j]: min = j arr [min], arr [I] = arr [I], arr [min] # exchange return arr my_list = [6, 23, 2, 54, 12, 6, 8,100] print (selection_sort (my_list ))