Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Replace with whitespace in string with only brackets solution in Clear category for Brackets by Wartem
def checkio(exp):
""" From the input exp, create a new string
with only the brackets allowed in it.
Replace all brackets in the new string
with empty strings.
Return True if the string is empty.
"""
b_list = ["()","[]","{}"]
b_str = ''.join(b for b in b_list)
b_in_exp = ""
for c in exp:
if c in b_str:
b_in_exp += c
while any(x in b_in_exp for x in b_list):
for b in b_list:
b_in_exp = b_in_exp.replace(b, "")
return not b_in_exp
May 29, 2022
Comments: