Sorting List with New Element Addition

  • Share this:

Code introduction


Define a function that accepts a list and a new element as parameters, adds the new element to the list, sorts the list, and returns the sorted list.


Technology Stack : List (list), Append (append), Sort (sort)

Code Type : Function

Code Difficulty : Intermediate


                
                    
def append_sort_list(a_list, new_element):
    a_list.append(new_element)
    a_list.sort()
    return a_list