Solution Exercise 36: Python program to delete multiple spaces


Write a program in Python to delete multiple spaces in a string


# Example of strings containing multiple spaces
s = " Python is object oriented a programming language"
# transform the string s to a python list
L = s.split()
#define an empty string s2
s2 = ""
# reconvert the list L in a chain by browsing the elements of the list.
for element in L:
s2 = s2 + element + " "
# The chain without multiple space
Younes Derfoufi

Leave a Reply