Alphabetical Sort Function

  • Share this:

Code introduction


This function takes a list as input and returns a new list that is sorted alphabetically. If `reverse=True` is set, the list will be sorted in reverse order.


Technology Stack : Built-in function `sorted()`, list

Code Type : Sort function

Code Difficulty : Intermediate


                
                    
def aord_items(items, reverse=False):
    """
    Sort a list of items alphabetically.

    :param items: List of items to be sorted.
    :param reverse: Boolean flag to reverse the sort order.
    :return: Sorted list of items.
    """
    sorted_items = sorted(items, reverse=reverse)
    return sorted_items