Skip to content

Commit 9807fca

Browse files
committed
adding balance parantheses
1 parent 03e8888 commit 9807fca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

paranthesesChecker.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ef check(expression):
2+
3+
open_tup = tuple('({[')
4+
close_tup = tuple(')}]')
5+
map = dict(zip(open_tup, close_tup))
6+
queue = []
7+
8+
for i in expression:
9+
if i in open_tup:
10+
queue.append(map[i])
11+
elif i in close_tup:
12+
if not queue or i != queue.pop():
13+
return "Unbalanced"
14+
return "Balanced"
15+
16+
# Driver code
17+
string = "{[]{()}}"
18+
print(string, "-", check(string))

0 commit comments

Comments
 (0)