Practice Makes Perfect


My code returns an error message: "Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "[***, ***, ***]" when it should return *** *** ***.

ignore all print commands. they're there because i wanted to check what and where it went wrong. Apparently the join command isn't working

the console:

['hey', 'hey', 'hey', 'buddy']
['***', '***', '***', 'buddy']
['***', '***', '***', 'buddy']

def censor(text, word):
    _list = text.split()
    print _list
    final = []
    for x in _list:
        if x == word:
            x = "*" * len(word)
            print x
    print final
    " ".join(final)
    print final
    return final

censor("hey hey hey buddy", "hey")


Have you tried simply doing this:
print " ".join(final)


thnx. that worked. i hadn't stored the data after the join() command. the program just joined and forgot about it.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.