for i in range(0,(len(list))):
x = str(list[i]).strip(' ')
list[i] = x
>>> import re
>>> re.sub(' +', ' ', 'The quick brown fox')
'The quick brown fox'
string=' t e s t '
print(string.replace(' ',''))
"
".join([s for s in code.split("
") if s])
#If you want to remove LEADING and ENDING spaces, use str.strip():
sentence = ' hello apple'
sentence.strip()
>>> 'hello apple'