Python: Insert spaces between words starting with capital letters
Python Regular Expression: Exercise-51 with Solution
Write a Python program to insert spaces between words starting with capital letters.
import re def capital_words_spaces(str1): return re.sub(r"(\w)([A-Z])", r"\1 \2", str1) print(capital_words_spaces("Python")) print(capital_words_spaces("PythonExercises")) print(capital_words_spaces("PythonExercisesPracticeSolution"))
Python Python Exercises Python Exercises Practice Solution
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?