Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in Python 3, Thanks! Consider a strings that contains a pair of matching parentheses with zero or more characters between the parentheses. Examples
Please write in Python 3, Thanks!
Consider a strings that contains a pair of matching parentheses with zero or more characters between the parentheses. Examples of such strings include: 'O 'a(bcd)efg' 'The professor (and her research assistant) solved an important problem.' 'x + ((y + z) / 2) * 10 Notice that the last example string contains a pair of nested parentheses. Write a recursive function get_enclosed(s) that returns the part of the strings that is enclosed by the outermost pair of matching parentheses including the parentheses. For each of the example strings shown above your function should return the following strings: '' '(bcd)' '(and her research assistant)' ((y + z) / 2)' Your function does not need to handle strings where there are two or more pairs of matching parentheses that are not nested. Examples of such input strings that you can ignore are: '(*_^)(^_^*)' 'a(bcd)(efg)hij(klm) '(x + y) * (y + z)' Finally, if the string does not contain a matching pair of parentheses then your function should return the empty string Examples of such input strings include: ^) abcdefghi abc[def]ghi You may use the string methods startswith and endswith, but your function should not use any other string methods (such as find or index )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