Censor problem


#1


Hi, I have a problem in Censor. No matter how I debug, I couldn't stop this wrong sign: Your function fails on censor("hey hey hey","hey"). It returns "" when it should return " *** ***".

def censor(text, word):
    l = len(word)
    whole = word.split()
    l2 = 0
    while l2 < len(whole):
        if whole[l2] == word:
            whole[l2] = "*" * l
        l2 += 1
    return " ".join(whole)

Could anyone help me find out the reason? Thx a lot!


#2

here:

whole = word.split()

what are you splitting from a string to a list? And why?


#3

oops...I can see where the problem is now... thank you so much! my silly mistake :-<


#4

you seem to have already reached the conclusion that you split the wrong thing. Good job. If silly mistakes where not made, programmers could code 50% faster, if not more.


#5

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