def matched(str):
    ope = []
clo = []
for i in range(0, len(str)):
    l = str[i]
if l == '(':
    ope = ope + ['(']
elif l == ')':
    clo = clo + [')']
if len(ope) == len(clo):
    return True
else:
    return False
Программа Python для проверки совпадения простых скобок