1 def isValid(s): 2 if s and len(s) % 2 is 0: 3 a = {')': '(', ']': '[', '}': '{'} 4 l = [None] 5 for i in s: 6 if i in a and a[i] == l[-1]: 7 l.pop() 8 else: 9 l.append(i) 10 return len(l) == 1 11 elif len(s) % 2 is 1: 12 return False 13 else: 14 return True