def precompute_pantsrefs(soups):
 accumulator = {}
 for (page, soup) in soups.items():
  existing_anchors = find_existing_anchors(soup)
  count = 100
  for tag in soup.find_all(u'a'):
   if tag.has_attr(u'pantsmark'):
    pantsmark = tag[u'pantsmark']
    if (pantsmark in accumulator):
     raise TaskError(u'pantsmarks are unique but "{0}" appears in {1} and {2}'.format(pantsmark, page, accumulator[pantsmark]))
    anchor = (tag.get(u'id') or tag.get(u'name'))
    if (not anchor):
     anchor = pantsmark
     while (anchor in existing_anchors):
      count += 1
      anchor = u'{0}_{1}'.format(pantsmark, count)
     tag[u'id'] = anchor
     existing_anchors = find_existing_anchors(soup)
    link = u'{0}.html#{1}'.format(page, anchor)
    accumulator[pantsmark] = link
 return accumulator

def precompute_pantsrefs ( soups ) : accumulator = { } for ( page , soup ) in soups . items ( ) : existing_anchors = find_existing_anchors ( soup ) count = 100 for tag in soup . find_all ( u'a' ) : if tag . has_attr ( u'pantsmark' ) : pantsmark = tag [ u'pantsmark' ] if ( pantsmark in accumulator ) : raise TaskError ( u'pantsmarks are unique but "{0}" appears in {1} and {2}' . format ( pantsmark , page , accumulator [ pantsmark ] ) ) anchor = ( tag . get ( u'id' ) or tag . get ( u'name' ) ) if ( not anchor ) : anchor = pantsmark while ( anchor in existing_anchors ) : count += 1 anchor = u'{0}_{1}' . format ( pantsmark , count ) tag [ u'id' ] = anchor existing_anchors = find_existing_anchors ( soup ) link = u'{0}.html#{1}' . format ( page , anchor ) accumulator [ pantsmark ] = link return accumulator
return links for <a pantsmark="foo"> tags .