Lexicographical String Comparison Function

  • Share this:

Code introduction


Compare two strings lexicographically and return the difference in alphabetical order. If a is less than b, return -1; if a is greater than b, return 1; if they are equal, return 0.


Technology Stack : String comparison

Code Type : Comparison function

Code Difficulty :


                
                    
def aordiff(a, b):
    """
    Compare two strings lexicographically and return the difference in alphabetical order.
    """
    return -1 if a < b else 1 if a > b else 0