10. Censor


Why is my code printing both the censored version of the text argument and the non-censored version? It should print only the censored input. Sorry if this code is a mess; I am not very good. Thank you for any help.

def censor(text,word):#defines variables as strings and takes input and moves to a list
    transient=inp.split(" ")  
    for i in range(len(transient)):#check each item in transient
        if transient[i]==remo:
    return " ".join(transient)

print censor("oh look a goldfish","goldfish")


your appending to the list which contains the original splitted string, this will give you the original string + censored version in one list

two options, append to a new list or replace words which require censoring (we can update elements in list using indexes)


Thank you. I created a new list and it now works.