Question: Write a function matched(s) that takes as input a string s and checks if the brackets ( and ) in s are matched: that is,
Write a function matched(s) that takes as input a string s and checks if the brackets "(" and ")" in s are matched: that is, every "(" has a matching ")" after it and every ")" has a matching "(" before it. Your function should ignore all other symbols that appear in s. Your function should return True if s has matched brackets and False if it does not.
Here are some examples to show how your function should work.
>>> matched("zb%78")
True
>>> matched("(7)(a")
False
>>> matched("a)*(?")
False
>>> matched("((jkl)78(A)&l(8(dd(FJI:),):)?)")
True
Step by Step Solution
3.44 Rating (154 Votes )
There are 3 Steps involved in it
Steps to write program 1Define the function in python using def keyword Define the fun... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
635df2f7e4f46_180220.pdf
180 KBs PDF File
635df2f7e4f46_180220.docx
120 KBs Word File
