avp26/u7/is_paired.py
2026-10-27 18:34:38 +01:00

15 lines
418 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def is_paired(input_string):
    duzki = {
        ')': '(',
        ']': '[',
        '}': '{'
    }
    zbirac = []
    for simbol in input_string:
        if simbol in duzki.values():
            zbirac.append(simbol)
        elif simbol in duzki:
            if not zbirac or zbirac.pop() != duzki[simbol]:
                return False
    return len(zbirac) == 0