punc_list = [".",";",":","!","?","/","\\",",","#","@","$","&",")","(","'","\""]
new_s = ''
for i in s:
if i not in punc_list:
new_s += i
return new_s.lower()
更換標點符號如果輸入如何使用空白
s = ("Hey! M'y nam;e i's")
我想輸出是:
s = ('hey m y name e i s')
我無法用空格代替PUNC
這個功課,還是可以使用正則表達式?另外,只是_exactly那些標點符號或_all_特殊字符? –
在'else'分支中,添加一個空白區域。 – DyZ
@tobias_k是的,它是作業。我正在考慮所有特殊字符 – Mar