xxxxxxxxxx
vals_inp=input()
list_set = list(vals_inp)
vals = [x for x in list_set if x != ' ']
set_vals = set(vals)
xxxxxxxxxx
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
xxxxxxxxxx
' hello world! '.strip()
'hello world!'
' hello world! '.lstrip()
'hello world! '
' hello world! '.rstrip()
' hello world!'
xxxxxxxxxx
# define a string with leading and trailing whitespace
my_string = ' Hello, world! '
# remove the leading and trailing whitespace
result = my_string.strip()
print(result) #prints Hello, world!
# remove the leading whitespace
result = my_string.lstrip()
print(result) #prints Hello, world!
# remove the trailing whitespace
result = my_string.rstrip()
print(result) #prints Hello, world!
xxxxxxxxxx
Use the strip() method
Example
>>> name = ' Steve '
>>> name
' Steve '
>>> name = name.strip()
>>> name
'Steve'
xxxxxxxxxx
import re
my_string = " Hello Python "
output = re.sub(r'^\s+|\s+$', '', my_string)
print(output)
xxxxxxxxxx
string= "women life freedom"
splited_list= string.split()
print(splited_list)