Program to add space between the words starting with capital letters

by | Dec 26, 2020 | Python Programs

Home » Python » Python Programs » Program to add space between the words starting with capital letters

Introduction

Given a string having no space in between the words and the starting letter of each word is capital.

add space between the words

Program

import re  
    
def check_str(ip_str):  
 
    ele = re.findall('[A-Z][a-z]*', ip_str)  
    output = []  
    for i in ele:  
        i = chr( ord (i[0]) + 32) + i[1:]  
        output.append(i)  
    print (' '.join(output)) 
        
ip_str = input("Enter the string: ")
check_str(ip_str)

Output

add space between the words Output

Explanation

In the above python code, we have used re.findall() function to extract the words starting with a capital letter from the given string and transformed each word to lower case. At last, we joined the words with space.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author