def remove_template(s):
 (n_open, n_close) = (0, 0)
 (starts, ends) = ([], [])
 in_template = False
 prev_c = None
 for (i, c) in enumerate(iter(s)):
  if (not in_template):
   if ((c == '{') and (c == prev_c)):
    starts.append((i - 1))
    in_template = True
    n_open = 1
  if in_template:
   if (c == '{'):
    n_open += 1
   elif (c == '}'):
    n_close += 1
   if (n_open == n_close):
    ends.append(i)
    in_template = False
    (n_open, n_close) = (0, 0)
  prev_c = c
 s = ''.join([s[(end + 1):start] for (start, end) in zip((starts + [None]), ([(-1)] + ends))])
 return s

def remove_template ( s ) : ( n_open , n_close ) = ( 0 , 0 ) ( starts , ends ) = ( [ ] , [ ] ) in_template = False prev_c = None for ( i , c ) in enumerate ( iter ( s ) ) : if ( not in_template ) : if ( ( c == '{' ) and ( c == prev_c ) ) : starts . append ( ( i - 1 ) ) in_template = True n_open = 1 if in_template : if ( c == '{' ) : n_open += 1 elif ( c == '}' ) : n_close += 1 if ( n_open == n_close ) : ends . append ( i ) in_template = False ( n_open , n_close ) = ( 0 , 0 ) prev_c = c s = '' . join ( [ s [ ( end + 1 ) : start ] for ( start , end ) in zip ( ( starts + [ None ] ) , ( [ ( - 1 ) ] + ends ) ) ] ) return s
remove template wikimedia markup .