Last active
March 22, 2017 04:48
-
-
Save okjodom/3b2c95e35802a8c1d65eb7949e44f6bc to your computer and use it in GitHub Desktop.
Finding Anagrams
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
| """ check if two words are anagrams """ | |
| def anagramIst(fword, sword): | |
| """ fword and sword are the first_word and the second_word respectively """ | |
| # messages | |
| negative = "The two words are not anagrams" | |
| positive = "The two words" + str(fword) + " , " + str(sword) +" are anagrams" | |
| #my interview implementation:: | |
| #first, do a check to compare the lengths: | |
| if len(fword) != len(sword): | |
| return negative | |
| else: | |
| #combine the two words and do a letter check for the entire word length:: | |
| combined = fword+sword | |
| for letter in combined: | |
| if letter not in fword or letter not in sword: | |
| return negative | |
| return positive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment