Skip to content

Instantly share code, notes, and snippets.

@awentzonline
Created August 13, 2014 16:01
Show Gist options
  • Select an option

  • Save awentzonline/a6db5706b97ac4d0c5cc to your computer and use it in GitHub Desktop.

Select an option

Save awentzonline/a6db5706b97ac4d0c5cc to your computer and use it in GitHub Desktop.
import re
re_normalize = re.compile('[\W]+')
def normalize_anagram(a):
a = a.lower()
a = re_normalize.sub('', a)
a = ''.join(sorted(a))
return a
def check_anagram(a, b):
"""
>>> check_anagram('taco', 'cato')
True
>>> check_anagram('cat', 'dog')
False
>>> check_anagram('The sunset is so beautiful!', 'shit butts i feel nauseous')
True
"""
return normalize_anagram(a) == normalize_anagram(b)
if __name__ == '__main__':
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment