Practice Makes Perfect


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


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']
None


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

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


#2

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


#3

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


#4

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