Simple Censor Program I made a function to censor a certain word from a piece of text. Is there anything I should fix or do more efficiently? What are some other approaches I could have taken to detecting words and censoring them?(This took me a lot of time to brainstorm)

Also, I would appreciate it if you told me how you brainstorm how to write a program.

def detect_word_start(text,word):
    count = 0
    text_count = 0
    for x in text:
        text_count+=1
        if x == word[count]:
            count+=1
            if count == len(word):
                return text_count - len(word) + 1
        else:
            count = 0

def censor(text,word):
    word_start = detect_word_start(text,word)
    censored_text = ''
    count = 0
    for x in text:
        count += 1
        if count &gt;= word_start and count &lt; word_start+len(word):
            censored_text += '*'
        else:
            censored_text += x
        print(censored_text)
Let's start by removing print from the loop and add a return value

def censor(text,word):
    #[...]
        else:
            censored_text += x
    return censored_text


now we have a testable function. we add some tests

import unittest

class TestSome(unittest.TestCase):

    def test_not_found(self):
        self.assertEqual(censor("", "bar"), "")
        self.assertEqual(censor("f", "bar"), "f")
        self.assertEqual(censor("foo", "bar"), "foo")
        self.assertEqual(censor("fooo", "bar"), "fooo")

    def test_found(self):
        self.assertEqual(censor("bar", "bar"), "***")
        self.assertEqual(censor("bar!", "bar"), "***!")
        self.assertEqual(censor("cow bar", "bar"), "cow ***")

    def test_parts(self):
        self.assertEqual(censor("foobar", "bar"), "foobar")
        self.assertEqual(censor("bare", "bar"), "bare")

    def test_capital(self):
        self.assertEqual(censor("Bar", "bar"), "***")

    def test_multiple(self):
        self.assertEqual(censor("foo bar bar foo", "bar"), "foo *** *** foo")

if __name__ == '__main__':
    unittest.main()


Running the tests show that the functions are not meeting my expectations. 


detect_word_start() does not return a value if nothing found
you miss words at the beginning of a sentence becaue of capitalization
you censor different words containing the character sequence
you miss multiple appearences