How to split a string on uppercase characters into a list with Python

2 Answers

0 votes
import re 
  
s = 'PythonJavaC#'

lst = re.findall('[A-Z][^A-Z]*', s) 
  
print(lst) 



'''
run:

['Python', 'Java', 'C#']

'''

 



answered Jan 4, 2020 by avibootz
0 votes
import re 
  
s = 'PythonJavaC#'

lst = [e for e in re.split("([A-Z][^A-Z]*)", s) if e] 
  
print(lst) 



'''
run:

['Python', 'Java', 'C#']

'''

 



answered Jan 4, 2020 by avibootz

Related questions

1 answer 354 views
2 answers 333 views
2 answers 381 views
2 answers 378 views
2 answers 282 views
1 answer 271 views
271 views asked Jul 28, 2023 by avibootz
...