def find_first_level_groups_span(string, enclosing):
 (opening, closing) = enclosing
 depth = []
 result = []
 for (i, c) in enumerate(string):
  if (c == opening):
   depth.append(i)
  elif (c == closing):
   try:
    start = depth.pop()
    end = i
    if (not depth):
     result.append((start, (end + 1)))
   except IndexError:
    pass
 return result

def find_first_level_groups_span ( string , enclosing ) : ( opening , closing ) = enclosing depth = [ ] result = [ ] for ( i , c ) in enumerate ( string ) : if ( c == opening ) : depth . append ( i ) elif ( c == closing ) : try : start = depth . pop ( ) end = i if ( not depth ) : result . append ( ( start , ( end + 1 ) ) ) except IndexError : pass return result
return a list of pairs for the groups delimited by the given enclosing characters .