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 174 views
1 answer 155 views
1 answer 152 views
4 answers 263 views
1 answer 154 views
1 answer 159 views
...