+ 1
This code solves every case except for the last one that is hidden .
The problem was to write a code that checks if the parentheses in an expression are balanced , and to do that with a stack, I didn't do that because I had this much easier code in mind: text = input() def balanced(text): for i in text: if text.count("(") ==text.count(")"): return True else: return False print(balanced(text)) What to improve to solve the last case?
3 odpowiedzi
+ 7
( ) ) (
Is it ok or not?
Opening brackets= closing brackets
+ 4
I remember having the same problem, maybe what that hidden case expects is that you use what the hint says, which is in fact the topic of the content being evaluated.
"You can use a simple list for a stack. Use list.insert(0, item) to push on the stack, and list.pop(0) to pop the top item. You can access the top element of the stack using list[0]."
+ 3
True, I changed my code based on what they asked for and it worked