Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!