Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brackets solution in Speedy category for Brackets by meastrojoshi
def checkio(text):
pattern = ['(', ')', '[', ']', '{', '}']
false = ['(}', '{)', '[}', '{]', '(]', '[)']
checking = [text[i] for i in range(len(text)) if text[i] in pattern]
checking = ''.join(checking)
if checking.count('(') != checking.count(')') or checking.count('[') != checking.count(']') or checking.count('{') != checking.count('}'):
return False
for i in range(len(false)):
if false[i] in checking:
return False
return True
'''def checkio(text):
pairs = [('(', ')'), ('[', ']'), ('{', '}')]
pattern = ['(', ')', '[', ']', '{', '}']
checking = [text[i] for i in range(len(text)) if text[i] in pattern]
if checking == []:
return True
if checking.count('(') != checking.count(')') or checking.count('[') != checking.count(']') or checking.count('{') != checking.count('}'):
return False
i = 1
while i in range(len(checking)):
if (checking[i-1],checking[i]) in pairs:
checking = checking[:i-1:] + checking[i+1::]
i -= 2
i += 1
if checking == []:
return True
elif i == len(checking) and checking != []:
return False'''
June 27, 2018