So I just finished the exercise #15.13.
After trying to hunt down an error Python was throwing up I decided to rewrite the whole thing. Which is the commented part in the code below, that works despite being a copy of the one above that throws up this error everytime its run
Traceback (most recent call last):
File "python", line 12, in
File "python", line 5, in censor
TypeError: object of type 'builtin_function_or_method' has no len()
The only difference I can spot is that the erroneous code has text=text.split() instead of s=text.spilt(). Which seems to be the cause of the error, my question now is why?
Shouldn't the initial text string get overwritten by the text=text.split() command and then behave like variable s in the the working code?
def censor(text,word): text=text.split cen='*'*len(word) for i in range(len(text)): if text[i]==word: text[i]=cen else: text[i]=text[i] return ' '.join(text) print censor("this is the strong string of strong", "strong") ''' word='strong' text="this is the strong string of strong" def censor(text,word): cen='*'*len(word) s= text.split() for i in range(len(s)): if s[i] == word: s[i] = cen else: s[i] == s[i] return ' '.join(s) print censor(text,word) '''