def is_kl_connected(G, k, l, low_memory=False):
 graphOK = True
 for edge in G.edges():
  (u, v) = edge
  if low_memory:
   verts = set([u, v])
   for i in range(k):
    [verts.update(G.neighbors(w)) for w in verts.copy()]
   G2 = G.subgraph(verts)
  else:
   G2 = copy.deepcopy(G)
  path = [u, v]
  cnt = 0
  accept = 0
  while path:
   cnt += 1
   if (cnt >= l):
    accept = 1
    break
   prev = u
   for w in path:
    if (w != prev):
     G2.remove_edge(prev, w)
     prev = w
   try:
    path = nx.shortest_path(G2, u, v)
   except nx.NetworkXNoPath:
    path = False
  if (accept == 0):
   graphOK = False
   break
 return graphOK

def is_kl_connected ( G , k , l , low_memory = False ) : graphOK = True for edge in G . edges ( ) : ( u , v ) = edge if low_memory : verts = set ( [ u , v ] ) for i in range ( k ) : [ verts . update ( G . neighbors ( w ) ) for w in verts . copy ( ) ] G2 = G . subgraph ( verts ) else : G2 = copy . deepcopy ( G ) path = [ u , v ] cnt = 0 accept = 0 while path : cnt += 1 if ( cnt >= l ) : accept = 1 break prev = u for w in path : if ( w != prev ) : G2 . remove_edge ( prev , w ) prev = w try : path = nx . shortest_path ( G2 , u , v ) except nx . NetworkXNoPath : path = False if ( accept == 0 ) : graphOK = False break return graphOK
returns true if and only if g is locally -connected .