DEV Community

Discussion on: Daily Challenge #51 - Valid Curly Braces

Collapse
 
rafaacioly profile image
Rafael Acioly • Edited

Python solution

from collections import Counter


def are_curly_braces_matched(braces: str) -> bool:
    closing_brace = '}'
    opening_brace = '{'

    if braces[0] == closing_brace:
        return False

    elements = Counter(braces)
    return elements.get(opening_brace) == elements.get(closing_brace)