0

help please Parenthesis equilibrated 2 days un this lesson

https://code.sololearn.com/cMeJ5wCU90s1/?ref=app

13th Jun 2022, 4:27 AM
Alejandro47
Alejandro47 - avatar
10 Respuestas
+ 1
class Stack: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def push (self,item): self.items.insert(0,item) def pop(self): return self.items.pop(0) def stack(self): return self.items def balanced (expression): s = Stack() for i in expression: if i == "(": s.push(i) if i == ")": if "(" in s.stack(): s.pop() else: return False if not s.stack(): return True else: return False print(balanced (input ()))
13th Jun 2022, 5:46 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
If there was more to edit, such as erasing lines, I would have said so :)
13th Jun 2022, 5:47 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
This is what you logically want to do if i == ")": if not "(" == s.pop(): return False You just need to add a stack underflow protection.
13th Jun 2022, 5:11 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
I dont see that working can u edit
13th Jun 2022, 5:26 AM
Alejandro47
Alejandro47 - avatar
0
if i == ")": if "(" in s.stack(): s.pop() else: return False
13th Jun 2022, 5:28 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
Thanks for trying yo help but you understand that the Code os long and It doesnt if ill erase the resto off lines ir what thats why there is a edit buttom to check
13th Jun 2022, 5:39 AM
Alejandro47
Alejandro47 - avatar
0
Now you lost me XD Too much auto-correction. I'm not sure what you want to say ...
13th Jun 2022, 5:41 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
Kakssjsj recently i erase all my phone data
13th Jun 2022, 5:43 AM
Alejandro47
Alejandro47 - avatar
0
Just edit the code to see that working I don't know if I have to erase the rest of lines
13th Jun 2022, 5:44 AM
Alejandro47
Alejandro47 - avatar
0
That code and giving minor error was so frustrating
13th Jun 2022, 5:55 AM
Alejandro47
Alejandro47 - avatar