Censor


#1



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


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 "'builtin_function_or_method' object is not iterable" error.


I am not iterating any in-built function. Why am I getting this error?


def censor(text,word):
    text_list=text.split
    for item in text_list:
        if item==word:
            item="*"* len(item)
    return "".join(text_list)


#2

here:

text_list=text.split

split() is a method, so it requires parentheses

item will give you read only values from the list, any changes made to item won't persist


#3

I am getting the following error:
Oops, try again. Your function fails on censor("Yo go fro yo go","go"). It returns "** ** fro yo go" when it should return "Yo ** fro yo **".

Where is it code execution failing? Please help.


#4

n has no way of knowing of its the right index to replace a word in the sentence

If you want to do this, use range() in the for loop to retrieve index values


#5

I got it right by using the below code. Thank you!


#6

impressive, i gave one small hint and you instantly solved it.


#7

I am a beginner in programming, your hints(without giving away the solution directly) help me a lot.


#8

many people would struggle with the hints, so that you can solve the exercise using my obscure hints is something you should be proud of :slight_smile:


#9

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