<p>在Python中,我一直在用空格替换“-”。我已经搜索了堆栈溢出并尝试了下面的代码,但它没有达到我想要的效果。在</p>
<pre><code>import string
text1 = ['why-wont-these-dashes-go-away']
for i in text1:
str(i).replace("-", " ")
print "output 1: "
print text1
text2 = ['why-wont-these-dashes-go-away']
text2 = [x.strip('-') for x in text2]
print "output 2: "
print text2
text3 = ['why-wont-these-dashes-go-away']
text3 = [''.join(c for c in s if c not in string.punctuation) for s in text3]
print "output 3: "
print text3
text4 = ['why-wont-these-dashes-go-away']
text4 = [' '.join(c for c in s if c not in string.punctuation) for s in text3]
print "output 4: "
print text4
</code></pre>
<p>以下是我的输出:</p>
^{pr2}$
<p>我想要的是:</p>
<pre><code>['why wont there dashes go away']
</code></pre>
<p>我知道text1、text2和text3每个列表都有一个字符串。可能是我忽略了一些小事,有什么想法吗?在</p>