xxxxxxxxxx
import re
my_string = " Hello Python "
output = re.sub(r'^\s+|\s+$', '', my_string)
print(output)
xxxxxxxxxx
text = " Example text with whitespace "
# Removing leading and trailing whitespace
trimmed_text = text.strip()
print(trimmed_text)
xxxxxxxxxx
sentence = ' hello apple'
" ".join(sentence.split())
>>> 'hello apple'
xxxxxxxxxx
>>> ' hello world! '.strip() #remove both
'hello world!'
>>> ' hello world!'.lstrip() #remove leading whitespace
'hello world!'
xxxxxxxxxx
Use the lstrip() method
>>> name = ' Steve '
>>> name
' Steve '
>>> name = name.lstrip()
>>> name
'Steve '
xxxxxxxxxx
vals_inp=input()
list_set = list(vals_inp)
vals = [x for x in list_set if x != ' ']
set_vals = set(vals)