def locate_unbalanced_start(unbalanced_start, pre_delete, post_delete):
 while 1:
  if (not unbalanced_start):
   break
  finding = unbalanced_start[0]
  finding_name = finding.split()[0].strip('<>')
  if (not post_delete):
   break
  next = post_delete[0]
  if ((next is DEL_START) or (not next.startswith('<'))):
   break
  if (next[1] == '/'):
   break
  name = next.split()[0].strip('<>')
  if (name == 'ins'):
   break
  assert (name != 'del'), ('Unexpected delete tag: %r' % next)
  if (name == finding_name):
   unbalanced_start.pop(0)
   pre_delete.append(post_delete.pop(0))
  else:
   break

def locate_unbalanced_start ( unbalanced_start , pre_delete , post_delete ) : while 1 : if ( not unbalanced_start ) : break finding = unbalanced_start [ 0 ] finding_name = finding . split ( ) [ 0 ] . strip ( '<>' ) if ( not post_delete ) : break next = post_delete [ 0 ] if ( ( next is DEL_START ) or ( not next . startswith ( '<' ) ) ) : break if ( next [ 1 ] == '/' ) : break name = next . split ( ) [ 0 ] . strip ( '<>' ) if ( name == 'ins' ) : break assert ( name != 'del' ) , ( 'Unexpected delete tag: %r' % next ) if ( name == finding_name ) : unbalanced_start . pop ( 0 ) pre_delete . append ( post_delete . pop ( 0 ) ) else : break
pre_delete and post_delete implicitly point to a place in the document .