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() +