Created
August 13, 2014 16:01
-
-
Save awentzonline/a6db5706b97ac4d0c5cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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