Bug: Python: Practice Makes Perfect: Censor


#1



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


If you use re, you can filter out parts of other words and the code still passes


If the operator decides to use re, the code should only pass if only the word as a whole is filtered out
Code below returns this: th** ** a sample sentence to censor
Change which 'res' line is commented out, returns this: this ** a sample sentence to censor


import re

def censor(text,word):
    length = len(word)
    #res = re.sub(r"\b%s\b" % word,"*"*length,text)
    res = re.sub(word,"*"*length,text)
    return res

print(censor("this is a sample sentence to censor","is"))


#2

unfortunately there are no such test cases, so its allowed. same with .replace()


#3

Ok, thanks for getting back to me :thumbsup:


#4

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