Fix matching brackets implementation

This commit is contained in:
Maksym Kurets 2026-10-13 20:21:00 +02:00
parent 7f81fa7032
commit b8252195f1
2 changed files with 13 additions and 1 deletions

12
u6/matching_brackets.py Normal file
View File

@ -0,0 +1,12 @@
def is_paired(input_string):
spisok = []
slovnik = {')': '(', ']': '[', '}': '{'}
for gnx in input_string:
if gnx in "([{":
spisok.append(gnx)
elif gnx in ")]}":
if not spisok or spisok[-1] != slovnik[gnx]:
return False
spisok.pop()