How to insert spaces between words that start with capital in a string with Python

2 Answers

0 votes
import re 
    
def insert_space(s): 
    words = re.findall('[A-Z][a-z]*', s) 

    return ' '.join(words) 
    
  
s = 'PythonJavaPascal'
print(insert_space(s))
     
     
     
'''
run:
     
Python Java Pascal
     
'''

 



answered Jan 14, 2020 by avibootz
edited Jan 15, 2020 by avibootz
0 votes
import re 
   
def insert_space(s): 
    words = re.findall('[A-Z][a-z]*', s) 
 
    s = ""
    for word in words: 
        s += word + ' '
    return s
   
 
s = 'PythonJavaPascal'
print(insert_space(s))
    
    
    
'''
run:
    
Python Java Pascal
    
'''

 



answered Jan 14, 2020 by avibootz
edited Jan 14, 2020 by avibootz
...