def node_boundary(G, nbunch1, nbunch2=None):
 nset1 = {n for n in nbunch1 if (n in G)}
 bdy = (set(chain.from_iterable((G[v] for v in nset1))) - nset1)
 if (nbunch2 is not None):
  bdy &= set(nbunch2)
 return bdy

def node_boundary ( G , nbunch1 , nbunch2 = None ) : nset1 = { n for n in nbunch1 if ( n in G ) } bdy = ( set ( chain . from_iterable ( ( G [ v ] for v in nset1 ) ) ) - nset1 ) if ( nbunch2 is not None ) : bdy &= set ( nbunch2 ) return bdy
returns the node boundary of nbunch1 .