Join method not joining on "Practice makes perfect"


My code seems to be working up until where I call the join method, where it doesn't join and just returns a list of *'s. Can't seem to find a way around this.

def censor(text,word):
    ns = text.split()
    for i in range(len(ns)):
        if word == ns[i]:
            ns[i] = '*' * len(ns)
    " ".join(ns)
    return ns


Method join does not mutate value of passed parameter. You have to assign result of this method to the variable:

ns = " ".join(ns)

ns[i] = '*' * len(ns)

Are you sure that it should be len(ns)? :slight_smile:


Ah for some reason I thought when I used the join function before it did. Whoops forgot the brackets. Thanks!


You're very welcome :slight_smile:


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