Given there aren't any examples of input and expected output, I had to make an assumption about desired behaviour.
detects any space IN BETWEEN the words and turn in to only three
space, no matter how many space the user typed between words.
It sounds like you want to look for any whitespace between words in a string and then massage that to have three spaces?
Here's a scrappy solution. It basically takes a string, splits it into individual words. We then create a list of words and adds three spaces after it (the f-string part). We can then can contaneate those new word-parts into a string. Then, finally, we can construct a sentence by joining the elements of words between the periods.
my_text = "Hello this is a test string with different amount of spaces between the words . Second sentence goes here ."
# Splits the string based on whitespace
list_of_words = my_text.split()
# List comprehension and f-string
list_of_words_with_spaces = [f'{word} ' for word in list_of_words]
new_string = ''
for word in list_of_words_with_spaces:
new_string += word
final_string = ''
for sentence in new_string.split('.'):
if not sentence.strip(): # Check to ignore for empty sentences
break
final_string += sentence[:-3] + '.' # Remove the whitespace before the period
The final string looks like this:
'Hello this is a test string with different amount of spaces between the words. Second sentence goes here.'