From b8252195f104151c0e4d118fbc4c7f3e970c2da5 Mon Sep 17 00:00:00 2001 From: Maksym Kurets Date: Tue, 13 Oct 2026 20:21:00 +0200 Subject: [PATCH] Fix matching brackets implementation --- u6/matching-brackets.py | 2 +- u6/matching_brackets.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 u6/matching_brackets.py diff --git a/u6/matching-brackets.py b/u6/matching-brackets.py index 7b647f9..e393c90 100644 --- a/u6/matching-brackets.py +++ b/u6/matching-brackets.py @@ -9,4 +9,4 @@ def is_paired(input_string): if not spisok or spisok[-1] != slovnik[gnx]: return False spisok.pop() - + diff --git a/u6/matching_brackets.py b/u6/matching_brackets.py new file mode 100644 index 0000000..e393c90 --- /dev/null +++ b/u6/matching_brackets.py @@ -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() +