Skip to content

Instantly share code, notes, and snippets.

@okjodom
Created March 22, 2017 04:50
Show Gist options
  • Save okjodom/ec49ac0b6390d7dfcd6e0dc2e6af7678 to your computer and use it in GitHub Desktop.
Save okjodom/ec49ac0b6390d7dfcd6e0dc2e6af7678 to your computer and use it in GitHub Desktop.
Fantastic Anagrams and Where to Find Them
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