Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Verify Anagrams by kuany88
def verify_anagrams(first_word, second_word):
#strip all white spaces in the second_word and first_word and make them lower case
first_word = first_word.lower()
second_word = second_word.lower()
first_word=first_word.replace(" ", "")
second_word=second_word.replace(" ", "")
#check length of each word, if length is not the same return false
length_a= len(first_word)
length_b= len(second_word)
if length_a != length_b:
return False
#Check the number of times each letter occur in each of the words. Make sure that they are the same
for i in first_word:
if first_word.count(i) != second_word.count(i):
return False
return True
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
#assert isinstance(verify_anagrams("a", 'z'), bool), "Boolean!"
assert verify_anagrams("Kings Lead Hat", "Talking Heads") == True, "Gram of code"
assert verify_anagrams("Hello", "Ole Oh") == False, "Hello! Ole Oh!"
assert verify_anagrams("Kyoto", "Tokyo") == True, "The global warming crisis of 3002"
Oct. 12, 2016