How can I use split( ) to make censor?


#1

Question

How can I use split( ) to make censor?

Answer

Just like join() uses the string it’s attached to to determine how to join together the string you provide in parentheses, split() does the same for splitting a string passed to it.
For example, if we have my_words_split = " ".split("first second third last"), the resulting list stored in my_words_split will be ["first", "second", "third", "last"].
We’ve done lots of work with lists, so the rest of this function is up to you, but remember to " ".join() your words back together at the end if you take this route!


FAQ: Learn Python - Practice Makes Perfect - censor
#2

A post was split to a new topic: Censor replacing using index


#3

2 posts were split to a new topic: Censor


#7
count = 0
for i in words:
    if i == word:
        words[count] = stars
    count += 1
result =' '.join(words)

Someone explain the count variable, how it works? Please.


#8

count is a variable to keep track of the index, so we can use it to update elements in words list

i would have named the variable index, not count.


#9

Yep! I understand …


#13

A post was split to a new topic: Function prints correct message but not working


#14

4 posts were split to a new topic: Censor


#18

A post was split to a new topic: Censor