Question
def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str You will be given three strings, the first string is a sentence knownas text that contains
def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str
You will be given three strings, the first string is a sentence knownas text that contains at least one occurrence of leftPatternand rightPattern. Left pattern and right patternare single characters strings that you are attempting to remove from the string. Your goal is to remove only thepatterns when the left pattern hasan equal number of correspondingright patterns. The patterns are removed in pairs only when there is a balanced number of left and right patterns. The patterns may be nested within the text and there is no guarantee that a left pattern will occur before the right pattern.
Example 1:
text ={ { Muscat } } { } mecum tollgate } poultry quarrymen pantheon asteria
leftPattern ={
rightPattern = }
return =Muscatmecum tollgate } poultry quarrymen pantheon asteria
Example 2:
text =theretofore [ ] [ ] demography ] ] pirouetting morsel [ [ pesticide
leftPattern =[
rightPattern = ]
return =.demography ] ] pirouetting morsel [ [ pesticide
Example 3:
text =( castigate ) alfonso ( ) ) ) emitter sourdough ) taco ( schemata
leftPattern =(
rightPattern = )
return =castigatealfonso) ) emitter sourdough ) Lauren ( schemata
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started