-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCa_censor.py
More file actions
39 lines (28 loc) · 781 Bytes
/
CodeCa_censor.py
File metadata and controls
39 lines (28 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def censor(text, word):
new = ''
lenght_term = len(term)
new_term = '*' * lenght_term
# split the text
text = text.split()
print text
# for each word in the line:
for item in text:
if item == word:
item = new_term
#print item
new += (new_term + " ")
else:
new += (item + " ")
return new[:len(new) - 1]
text = "hey hey hey"
term = "hey"
print censor(text, term)
# another version that passed on codecademy portal. it uses 'replace' function
def censor(text, word):
word_old = word
for letter in word:
word = word.replace(letter, '*')
while word_old in text:
if word_old in text:
text = text.replace(word_old, word)
return text