Traceback (most recent call last):
File “python”, line 7, in < module>
File “python”, line 6, in censor
AttributeError: ‘list’ object has no attribute ‘join’

This is obviously not the right way to do it, but I am a bit stuck. I don’t know why my .split on line 2 doesn’t count as an attribute to join. I am trying to get “word” to be censored which in this case is “time”. I may have misunderstood the assignment though.

def censor(text, word):
  words = word.split() 
  for i in range(len(words)):
    if words[i] in word:
      words[i] = "*" * len(words[i])
      text = words.join()
print censor("snack", "time") 


look at this example:

my_list = ['a', 'b', 'c']
print "-".join(my_list)

the "-" before join is the string we use to stitch the list together, if you run the code you will get the following output:


see how the hyphen is used to join the elements of list into string?

then between the parentheses of join, we specify the list we want to join

see the difference with your code?


Okay, I changed it to the following. I forgot that you had to put the string inside the parentheses.

text = ' '.join(words)

It still returns None, though. Does the rest of the code look completely off? I also tried to change line 2; to split text instead, but with no luck.


i work one step at a time, the more you do, the more you learn

By default, a function returns None at the end. If we want to return something else at the end of the function, we can use the return keyword


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