#sort_list_shorter.py
#This introduces some new Python functions:  max(), min(), .index(), .append()  and .reverse()
import random
import sys
import os

my_list = [14, 55, 3, 99, 7, 18]
wrk_list = list(my_list)  #make a copy of the list so that the original list is not changed
num_in_list = len(wrk_list)  #find the number of items in the list

wrk_list_index = 0  #set the wrk_list index to zero to be used when the loop starts
sorted_list = []  #create an empty list, values will be appended to it


min_val = min(wrk_list)  
replace_val = min_val-1
      # used to replace values in wrk_list so that they will be ignored by the Python "max()" function later

while(wrk_list_index < num_in_list):
    max_val = max(wrk_list)  # Use the Python "max()" function to find the largest value in wrk_list
    max_val_index = wrk_list.index(max_val) #use Python list.index() to find the index of max_val in wrk_list
    wrk_list[max_val_index] = replace_val  #Replace the maximum value in the wrk_list with the replacement
                                           #value so that it will be ignored in the future loop cycles.
    wrk_list_index = wrk_list_index + 1    #increment the wrk_list_index by 1 to be used in the next cycle of the loop
    
    sorted_list.append(max_val)  #Use the Python  list.append() to append
             # a value to the end of the sorted_list


print("\nOriginal list was   : ",my_list)
print("Sorted list is      : ",sorted_list)

#the sorted list can be put in reverse order (lowest to highest) with the Python "reverse" function.
sorted_list.reverse()
print("\nThe sorted list in reverse order is : ",sorted_list)

#the Python function .sort will sort a list in one step
sorted_list2 = list(my_list)
print("\nThe list to be sorted by sort() is    : ",sorted_list2)
sorted_list2.sort()
print("The list from the .sort() function is : ", sorted_list2)
    
    
   

