+ 2
String
A string with parentheses is well bracketed if all parentheses are matched: every opening bracket has a matching closing bracket and vice versa. Write a Python function wellbracketed(s) that takes a string s containing parentheses and returns True if s is well bracketed and False otherwise. Hint: Keep track of the nesting depth of brackets. Initially the depth is 0. The depth increases with each opening bracket and decreases with each closing bracket. What are the constraints on the value of the nesting
3 ответов
+ 3
@lunarCoffee but in your solution ' )()( ' this will return true
+ 1
well_bracketed = lambda s: True if s.count("(") == s.count(")") else False
should [EDIT:not] work fine
+ 1
I need to go rn, ill be back in ~1 hour