我需要带一个字符串,任何字符串,并用 空格 替换所有标点符号(',.!"
等)。
所以,如果我的字符串最初是
"sally sells seashells... but she's afraid of water"
输出需要
"sally sells seashells but she s afraid of water"
我们被告知要将s转换为列表,并使用包含if-block的for循环来执行此操作。
s = "She sells seashells... but at home she's afraid of water."
alph = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def removePunctuation(s):
slist = list(s)
for i in slist:
if i not in alph:
slist.replace(i, ' ')