Skip to content

Instantly share code, notes, and snippets.

@abdulateef
Last active December 9, 2018 11:28
Show Gist options
  • Save abdulateef/921744dae2b34c102f0cfeb8b10478d2 to your computer and use it in GitHub Desktop.
Save abdulateef/921744dae2b34c102f0cfeb8b10478d2 to your computer and use it in GitHub Desktop.
Create a method using Python 2.7.x syntax called is_isogram that takes one argument, a word to test if it's an isogram. This method should return a tuple of the word and a boolean indicating whether it is an isogram. If the argument supplied is an empty string, return the argument and False: (argument, False). If the argument supplied is not a s…
def is_isogram(word):
#to get the type of word
if type(word)!=str:
#print error
raise TypeError("Argument should be a String")
#remove space
elif word.strip()=="":
return(word,False)
else:
#change to lower case
word =word.lower()
#check each letter in word
for char in word:
#count the number of words
if word.count(char) > 1:
return (word ,False)
else:
return(word ,True)
print(is_isogram('Machine'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment