python-checkio/ScientificExpedition/verify-anagrams.py
2019-12-18 21:06:22 +01:00

18 lines
763 B
Python

def verify_anagrams(first_word, second_word):
first_word = first_word.replace(" ", "").lower()
second_word = list(second_word.replace(" ", "").lower())
for letter in first_word:
if letter in second_word:
second_word.remove(letter)
else:
return False
return len(second_word) == 0
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("Programming", "Gram Ring Mop") == 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"