Last active
May 26, 2017 08:22
-
-
Save mortymacs/e6b5664ad6fb6b3174dfb186f4ec6a5f to your computer and use it in GitHub Desktop.
Simple Anagram in Python
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
| def anagram(str1, str2): | |
| str1 = str1.replace(" ", "").lower() | |
| str2 = str2.replace(" ", "").lower() | |
| if str1 == str2: | |
| return True | |
| if len(str1) != len(str2): | |
| return False | |
| for l in list(str1): | |
| str2 = str2.replace(l, "") | |
| str1 = str1.replace(l, "") | |
| if str1.strip() == str2.strip(): | |
| return True | |
| return False | |
| anagram("public relations", "crap built on lies") | |
| # True | |
| anagram("Cook", "Book") | |
| # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment