diff --git a/u6/matching_brackets.py b/u6/matching_brackets.py new file mode 100644 index 0000000..4eed9dd --- /dev/null +++ b/u6/matching_brackets.py @@ -0,0 +1,16 @@ +PARY = {")": "(", "]": "[", "}": "{"} +OTVARACIE = set(PARY.values()) + + +def is_paired(input_string): + zasobnik = [] + + for znak in input_string: + if znak in OTVARACIE: + zasobnik.append(znak) + elif znak in PARY: + if not zasobnik or zasobnik.pop() != PARY[znak]: + return False + + return not zasobnik +