Python: Remove the parenthesis area in a string
Write a Python program to remove the parenthesis area in a string.
Sample Solution:-
Python Code:
import re
items = ["example (.com)", "w3resource", "github (.com)", "stackoverflow (.com)"]
for item in items:
print(re.sub(r" ?\([^)]+\)", "", item))
Sample Output:
example w3resource github stackoverflow
Pictorial Presentation:
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to remove words from a string of length between 1 and a given number.
Next: Write a Python program to insert spaces between words starting with capital letters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics