import re space_pat = re.compile(r'\s{2,}') print(space_pat.sub(' ','This string inсludes extra spaces'))
s = input() print(s.strip())
a = input('Enter string') print((' ').join(word for word in a.split(' ') if word != ''))
>>> s = ' abc def ghi ' >>> out = ' '.join(s.split()) >>> out 'abc def ghi' >>>
b=" bb ".strip() print(b)
>>>beatles = ["John", "Paul", "Ringo", "George"] >>> s = ", ".join(beatles[:-1]) + " & " + beatles[-1] + "." >>> print(s) John, Paul, Ringo & George. >>>
beatles = ["John"]