Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Without 3rd party. Short and readable. solution in Clear category for Remove Brackets by GrigorySol
def remove_brackets(line: str) -> str:
brackets = {')': '(', ']': '[', '}': '{'}
pared = ''
if 0 <= len(line) <= 1:
return ''
for i in reversed(range(len(line))):
closing = line[i]
if closing in brackets and brackets[closing] in line:
opening = brackets[closing]
if i - line.rindex(opening) == 1:
pared = opening + closing + pared
else:
pared = opening + remove_brackets(line[line.index(opening)+1: i]) + closing
return pared
line = line[:i]
return pared
Nov. 13, 2020
Comments: