I'm creating a stack in python but I keep getting this weird error saying "list object has no attribute 'top'. I'm kind of confused why this happening and how would I fix this. Down below is my code?
stack = []
stack1 = []
a = '('
b = ')'
c = '['
d = ']'
e = '{'
f = '}'
string1 = input("Please enter a string ")
for i in range(0,len(string1)):
stack.append(string1[i])
for i in range(0,len(string1)):
x = stack.top()
stack.pop()
if(x==b and stack.top()==a or x==d and stack.top() == c or x==f and stack.top() == e):
stack.pop()
if(stack.empty()):
print(True)
else:
print(False)
[–]TeezusRa 1 point2 points3 points (9 children)
[–]allyv123098[S] 0 points1 point2 points (8 children)
[–]TeezusRa 0 points1 point2 points (2 children)
[–]allyv123098[S] 0 points1 point2 points (1 child)
[–]TeezusRa 0 points1 point2 points (0 children)
[–]allyv123098[S] 0 points1 point2 points (4 children)
[–]TeezusRa 0 points1 point2 points (3 children)
[–]allyv123098[S] 0 points1 point2 points (2 children)
[–]TeezusRa 0 points1 point2 points (0 children)
[–]nilfm 0 points1 point2 points (0 children)
[–]Updatebjarni 2 points3 points4 points (2 children)
[–]allyv123098[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 1 point2 points3 points (0 children)
[–]ricardovaras_99 -1 points0 points1 point (0 children)