def count_unbalanced_brackets(line):
 count = 0
 for (opening, closing) in [u'()', u'[]', u'{}']:
  count += abs((line.count(opening) - line.count(closing)))
 return count

def count_unbalanced_brackets ( line ) : count = 0 for ( opening , closing ) in [ u'()' , u'[]' , u'{}' ] : count += abs ( ( line . count ( opening ) - line . count ( closing ) ) ) return count
return number of unmatched open/close brackets .