Join method not joining on "Practice makes perfect"


#1



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


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


#2

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:


#3

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


#4

You're very welcome :slight_smile:


#5

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