and each time through the loopwe select the smallest of the remaining elements and move it into its proper position applying this idea to list of elementswe proceed by finding the smallest value in the list and putting it into the th position then we find the smallest remaining value (from positions -( - )and put it in position nextthe smallest value from positions -( - goes into position etc when we get to the end of the listeverything will be in its proper place there is one subtlety in implementing this algorithm when we place value into its proper positionwe need to make sure that we do not accidentally lose the value that was originally stored in that position for exampleif the smallest item is in position moving it into position involves an assignment nums[ nums[ but this wipes out the value currently in nums[ ]it really needs to be moved to another location in the list simple way to save the value is to swap it with the one that we are moving using simultaneous assignmentthe statement nums[ ]nums[ nums[ ]nums[ places the value from position at the front of the listbut preserves the original first value by stashing it into location using this ideait is simple matter to write selection sort in python will use variable called bottom to keep track of which position in the list we are currently fillingand the variable mp will be used to track the location of the smallest remaining value the comments in this code explain this implementation of selection sortdef selsort(nums)sort nums into ascending order len(numsfor each position in the list (except the very lastfor bottom in range( - )find the smallest item in nums[bottomnums[ - mp bottom for in range(bottom+ , )if nums[inums[mp]mp bottom is smallest initially look at each position this one is smaller remember its index swap smallest item to the bottom nums[bottom]nums[mpnums[mp]nums[bottomone thing to notice about this algorithm is the accumulator for finding the minimum value rather than actually storing the minimum seen so farmp just remembers the position of the minimum new value is tested by comparing the item in position to the item in position mp you should also