Why do we need to use a count variable in censor?


#1

Question
Why do we need to use a count variable in censor instead of, say, just replacing the word with the stars?

Solution=
if i == word:
            words[count] = stars
        count += 1
Why not=
if i==word:
          i='*'*len(word)

FAQ: Learn Python - Practice Makes Perfect - censor
How can I use split( ) to make censor?
#2

because the value stored in i is a copy, any change made to it won’t persist. We need to update the words list. Updating lists is done using indexes, for which we use count variable


#3

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