Created
March 22, 2017 04:50
-
-
Save okjodom/ec49ac0b6390d7dfcd6e0dc2e6af7678 to your computer and use it in GitHub Desktop.
Fantastic Anagrams and Where to Find Them
This file contains 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 betterAnagramIst(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: | |
#sort the two words and check for equality | |
fword_sorted = ''.join(sorted(fword)) | |
sword_sorted = ''.join(sorted(sword)) | |
if fword_sorted == sword_sorted: | |
return positive | |
return negative | |
##Aand voila! a solution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment