def _collapse_addresses_internal(addresses):
 to_merge = list(addresses)
 subnets = {}
 while to_merge:
  net = to_merge.pop()
  supernet = net.supernet()
  existing = subnets.get(supernet)
  if (existing is None):
   subnets[supernet] = net
  elif (existing != net):
   del subnets[supernet]
   to_merge.append(supernet)
 last = None
 for net in sorted(subnets.values()):
  if (last is not None):
   if (last.broadcast_address >= net.broadcast_address):
    continue
  (yield net)
  last = net

def _collapse_addresses_internal ( addresses ) : to_merge = list ( addresses ) subnets = { } while to_merge : net = to_merge . pop ( ) supernet = net . supernet ( ) existing = subnets . get ( supernet ) if ( existing is None ) : subnets [ supernet ] = net elif ( existing != net ) : del subnets [ supernet ] to_merge . append ( supernet ) last = None for net in sorted ( subnets . values ( ) ) : if ( last is not None ) : if ( last . broadcast_address >= net . broadcast_address ) : continue ( yield net ) last = net
loops through the addresses .