A more thorough method involves comparing the words character by character. Below is an example code snippet demonstrating this approach: def areWordsSorted ( word1 , word2 ) : word1 = word1 . lower ( ) word2 = word2 . lower ( ) # compare the words character by character for a , b in zip ( word1 , word2 ) : if a < b : return True elif a > b : return False # If we've reached this point, it means word1 is either equal to word2 or is a prefix of word2 if len ( word1 ) <= len ( word2 ) : return True else : return False This function operates similarly to the previous one. It first converts both words to lowercase, then compares each character of the words sequentially. If it encounters a character in word1 that is lexicographically greater than the corresponding character in word2 , it returns False . If it completes the comparison without finding such a pair, it returns True if word1 is shorter than or equal in length to word2 ; otherwise, it returns False . This handles scenarios where one word is a prefix of the other, such as 'apple' and 'apples'.