I'm stuck on replacing "-" with whitespace in Python. I've searched Stack Overflow and tried the code below, but it doesn't do what I want.
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
Here's my output:
output 1:
['why-wont-these-dashes-go-away']
output 2:
['why-wont-these-dashes-go-away']
output 3:
['whywontthesedashesgoaway']
output 4:
['w h y w o n t t h e s e d a s h e s g o a w a y']
Here's what I want:
['why wont there dashes go away']
I know text1, text2, and text3 are each lists with one item which is a string. It's probably something small I'm overlooking, any ideas?