How to split string and remove whitespace in Python

1 Answer

0 votes
string = 'python- java-  c-     -php--  javascript   -    c++'

lst = [word.strip() for word in string.split('-')]

print(lst) 



'''
run:

['python', 'java', 'c', '', 'php', '', 'javascript', 'c++']

'''

 



answered Aug 7, 2022 by avibootz

Related questions

2 answers 187 views
1 answer 166 views
1 answer 160 views
4 answers 285 views
1 answer 167 views
1 answer 175 views
...