How to split string on whitespace in Python

2 Answers

0 votes
s = " Python  interpreted   programming   language"

lst = s.split()

print(lst)


     
'''
run:
     
['Python', 'interpreted', 'programming', 'language']

'''

 



answered Apr 12, 2021 by avibootz
0 votes
import re

s = " Python  interpreted   programming   language"

lst = re.findall(r'\S+', s)

print(lst)


     
'''
run:
     
['Python', 'interpreted', 'programming', 'language']

'''

 



answered Apr 12, 2021 by avibootz
...