def deflood(s, n=3):
 if (n == 0):
  return s[0:0]
 return re.sub(('((.)\\2{%s,})' % (n - 1)), (lambda m: (m.group(1)[0] * n)), s)

def deflood ( s , n = 3 ) : if ( n == 0 ) : return s [ 0 : 0 ] return re . sub ( ( '((.)\\2{%s,})' % ( n - 1 ) ) , ( lambda m : ( m . group ( 1 ) [ 0 ] * n ) ) , s )
returns the string with no more than n repeated characters .