How to split string by one or more adjacent new lines in Python

2 Answers

0 votes
import re

s = '''python



java



c++


c'''

s = re.split('\n+', s)
 
print(s)
 
 
 
'''
run:
 
['python', 'java', 'c++', 'c']
 
'''

 



answered Oct 26, 2020 by avibootz
0 votes
import re

s = 'python\n\n\njava\n\nc++\n\n\n\nc'

s = re.split('\n+', s)
 
print(s)
 
 
 
'''
run:
 
['python', 'java', 'c++', 'c']
 
'''

 



answered Oct 26, 2020 by avibootz

Related questions

1 answer 165 views
1 answer 139 views
1 answer 185 views
1 answer 124 views
1 answer 92 views
...