Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Verify Anagrams by anplaceb
from collections import Counter
import re
def verify_anagrams(first_word, second_word):
regex = re.compile('[^a-zA-Z]') # pattern for only letters
first_word = regex.sub('', first_word).lower() # string only containg lower case letters
second_word = regex.sub('', second_word).lower()
# Counter creates a dictionary that counts number of times a letter is in a string
if Counter(first_word) == Counter(second_word):
return True
else:
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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"
Nov. 10, 2019
Comments: