[英]Changing Punctuation to White space(space character)
As of now it takes the punctuation out, but I cannot figure out how to make it add a space instead of just taking out the punctuation. 到目前为止,它已经删除了标点符号,但是我不知道如何使它添加一个空格,而不是仅仅删除标点符号。 Currently I have: 目前我有:
punctuation = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~"
def remove_punct(theStr):
theStr_sans_punct = ""
for letter in theStr:
if letter not in punctuation:
theStr_sans_punct = theStr_sans_punct + letter
return theStr_sans_punct
It's in a interactive textbook so it will automatically do the tests on their site. 它位于交互式教科书中,因此它将自动在其站点上进行测试。
By adding an else
to your code: 通过在代码中添加else
代码:
punctuation = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~"
def remove_punct(theStr):
theStr_sans_punct = ""
for letter in theStr:
if letter not in punctuation:
theStr_sans_punct = theStr_sans_punct + letter
else:
theStr_sans_punct = theStr_sans_punct + " "
return theStr_sans_punct
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.