- #1
tabc
- 5
- 0
Homework Statement
Write a function spacereplace(txt) that removes two or more spaces in a row, replacing them with a single space. Any other characters should remain the same.
The Attempt at a Solution
I tried this:
def spacereplace(txt):
f=txt.replace(" "," ")
return f
This obviously just works when there are two spaces. I have no idea how to make it work for 2+.
This method apparently works:
def spacereplace(txt):
txt.split()
f=" ".join(txt.split())
return f
But it is not beeing accepted. Any ideas?