Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Third solution in Uncategorized category for Brackets by ilih
# migrated from python 2.7
def checkio(Expression):
'Check expression for correct brackets order'
starts = '{[('
ends = '}])'
b = []
for s in Expression:
if s in starts:
b.append(ends[starts.index(s)])
elif s in ends:
if len(b)==0:
return False
if s==b[-1]:
del b[-1]
else:
return False
if len(b)==0:
return True
return False
print('First','Done' if checkio('({(asda)sd[s]d})') else 'Wrong')
print('Second','Done' if checkio('({[a]((s)})') else 'Wrong')
April 13, 2011
Comments: