Write a Python program which delete all multiple spaces in a given string ‘s’.
# define a string with multiple spaces s = "Hello world! How are you?" # delete the multiple space in the string s s = " ".join(s.split()) print(s)
- The program uses the split() method: to split the string into a list of words.
- Then, it uses join() method: to join the words back into a string with a single space between them.
- The output will be: “Hello world! How are you?”.
One thought on “Solution Exercise 36: python algorithm to delete mumtiple spaces”
[…] Exercice36 || Solution […]