I want to write code that will remove extraneous spaces in a string. Any more than 1 space in between words would be an extraneous space. I want to remove those spaces but keep 1 space in between words
I've written code that will remove spaces at the beginning and the end but I'm not sure for to make it remove the middle spaces but keep 1 there.
#Space Cull
def space_cull(str):
result = str
result = result.strip()
return result
So this is what my code does right now
space_cull(' Cats go meow ')
#It would return
'Cats go meow'
What I want it to do is this:
space_cull(' Cats go meow')
#It would return
'Cats go meow'
How should I do this?