Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Python function for isogram

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 string, raise a TypeError with the message 'Argument should be a string'.

Example:

is_isogram("abolishment") Expected result:

("abolishment", True)

Here is the code; what could I be missing?

def is_isogram(word): if not isinstance (word, str): raise TypeError ("This should be a string") if not word: isogram = True else: isogram = len(word) == len(set(word.lower())) return(word, isogram)

1 Answer

Like you mentioned, for an empty string, return the argument and False: (argument, False).

Except this everything seems to be working fine. I do not understand what else is your concern.

As for empty string:

def is_isogram(word):
     if not isinstance (word, str):
             raise TypeError ("This should be a string")
     if not word:
             isogram = False
     else:
             isogram = len(word) == len(set(word.lower()))
     return(word, isogram)