Skip to content

Instantly share code, notes, and snippets.

@okjodom
Last active March 22, 2017 04:48
Show Gist options
  • Select an option

  • Save okjodom/3b2c95e35802a8c1d65eb7949e44f6bc to your computer and use it in GitHub Desktop.

Select an option

Save okjodom/3b2c95e35802a8c1d65eb7949e44f6bc to your computer and use it in GitHub Desktop.
Finding Anagrams
""" 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