Python: Remove lowercase substrings from a given string
Python Regular Expression: Exercise-53 with Solution
Write a Python program to remove lowercase substrings from a given string.
Sample Solution:
Python Code:
import re
str1 = 'KDeoALOklOOHserfLoAJSIskdsf'
print("Original string:")
print(str1)
print("After removing lowercase letters, above string becomes:")
remove_lower = lambda text: re.sub('[a-z]', '', text)
result = remove_lower(str1)
print(result)
Sample Output:
Original string: KDeoALOklOOHserfLoAJSIskdsf After removing lowercase letters, above string becomes: KDALOOOHLAJSI
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to insert spaces between words starting with capital letters.
Next: Write a Python program to concatenate the consecutive numbers in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/re/python-re-exercise-53.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics