10. censor


#1

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

can anyone plese explain how to work with

string.split()
or
" ".join(list)

def censor(text , word ) :
    n = len(word)
    a = '*' * n
    for word in censor:
        text.split(word)
        return text + a
        
    return censor

Oops, try again. Does your censor function take exactly two arguments, a text string and a word to replace with asterisks? Your code threw a "'function' object is not iterable" error.

I can't get my code to work


#2

split() splits a sting into a list
join() joins a list to a string

see the docs:

join
split


#3

Thank you!
so should I use it like this:

def censor(text , word ) :
    n = len(word)
    a = '*' * n
    for word in censor:
        censor.split(text)
        return text + a
        
    return censor

#4

so our function has two parameters: text and word. text is a string, and word is a word which we want to censor from our string (text)

So then it would make sense to first split our string (text) into a list.

Then loop over the list (you loop over the function, how does that work?), that should already be huge improvements to your program


#5

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