Return list of all nodes on external boundary of nbunch1 that are in nbunch2. If nbunch2 is omitted or nbunch2=None, then nbunch2 is all nodes not in nbunch1. Note that by definition the node_boundary is external to nbunch1. Nodes in nbunch1 and nbunch2 that are not in the graph are ignored. nbunch1 and nbunch2 must be disjoint (when restricted to the graph), else a NetworkXError is raised. Definition at line 762 of file base.py. 00762 : """Return list of all nodes on external boundary of nbunch1 that are in nbunch2. If nbunch2 is omitted or nbunch2=None, then nbunch2 is all nodes not in nbunch1. Note that by definition the node_boundary is external to nbunch1. Nodes in nbunch1 and nbunch2 that are not in the graph are ignored. nbunch1 and nbunch2 must be disjoint (when restricted to the graph), else a NetworkXError is raised. """ bdy=[] # listify to avoid exhausting a oncethrough iterable container # nlist1 and nlist2 contains only nodes that are in the graph nlist1=[n for n in nbunch1 if n in self] len1=len(nlist1) if nbunch2 is None: # use nbunch2 = complement of nbunch1 nlist2=[n for n in self if n not in nlist1] len2=len(nlist2) # size of node complement else: nlist2=[n for n in nbunch2 if n in self] len2=len(nlist2) # check for nonempty intersection: # nbunch1, nbunch2 and self.nodes() should have no nodes # in common # use shortest outer loop if len1 <= len2: for n in nlist1: if n in nlist2: raise NetworkXError,\ "nbunch1 and nbunch2 are not disjoint" else: for n in nlist2: if n in nlist1: raise NetworkXError,\ "nbunch1 and nbunch2 are not disjoint" # use shortest outer loop if len1 <= len2: # find external boundary of nlist1 for n1 in nlist1: for n2 in self.adj[n1]: if (not n2 in bdy) and (n2 in nlist2): bdy.append(n2) else: # find internal boundary of nlist2 for n2 in nlist2: if not n2 in bdy: for n in self.adj[n2]: if n in nlist1: bdy.append(n2) break return bdy def degree(self,nbunch=None,with_labels=False):
