📜  python代码示例中的括号平衡与否

📅  最后修改于: 2022-03-11 14:45:23.510000             🧑  作者: Mango

代码示例1
def isBalanced(final_str):
    type_brackets = ['()', '{}', '[]']
    while any(x in final_str for x in type_brackets):
        for br in type_brackets:
            final_str = final_str.replace(br, '')
    return not final_str


string = "{[]{()}}"
print(string, "-", "Balanced"
      if isBalanced(string) else "Unbalanced")