r/pythonhelp • • Dec 14 '17

Am I doing something wrong?

I'm working through some problems on a site calledexercism.io, and essentially I have to check whether a word is an isogram or not.

Here is the solution I have.

Here is the class I'm testing it against.

I'm really at a loss on what I've done incorrectly. Could anyone shed some light? Thank you.

0 Upvotes

1 comment sorted by

View all comments

2

u/novel_yet_trivial Dec 14 '17 edited Dec 14 '17

Your logic is fine. It's just that you are returning 2 things: the string and the result boolean, but your test case is comparing that to a boolean only. Try it like this:

def is_isogram(string):
    string = string.lower().replace(" ","").replace("-","")
    if len(string) == len(set(string)):
        return True
    else:
        return False

Or the same but much simpler:

def is_isogram(string):
    string = string.lower().replace(" ","").replace("-","")
    return len(string) == len(set(string))

Edit: also, your test cases should probably be using assertEqual.