我試圖做一個簡單的程序,它的文本噸的字符串和文字升的列表,並打印文本,但與對應的字母許多的X.替換升的話在這個詞裏。使用字典檢查文本字符串並用X替換單詞。 Python的
問題:我的代碼也會替換部分匹配l中的單詞的單詞。我怎樣才能讓它只瞄準整個單詞?
def censor(t, l):
for cenword in l:
number_of_X = len(cenword)
sensurliste = {cenword : ("x"*len(cenword))}
for cenword, x in sensurliste.items():
word = t.replace(cenword, x)
t = word.replace(cenword, x)
print (word)
clbuttic錯誤 – mata
@mata護理闡述?編程新手。 – user2406501
[谷歌它](https://www.google.com/search?q=clbuttic+mistake):) – mata