---> 17 elif d[char] == stack[-1]: TypeError: 'set' object is not subscriptable
wrote the same code but always getting and error
def balanced_stack(s):
stack = []
d = {'(',')',
'[',']',
'{','}' ,}
for char in s:
if not stack:
stack.append(char)
print('if not stack char = ', char)
elif char not in d:
stack.append(char)
print('elif char not in d char = ', char)
elif d[char] == stack[-1]:
stack.pop()
print('elif dchar stack char = ', char)
else:
stack.append(char)
print('else char = ', char)
if not stack:
return True
else:
return False
Hey Yousif,
Thank you for your question!
Could you please take a screenshot of your code in the Jupyter notebook and the error you are getting?
Thank you!
Kind regards,
365 Hristina