title: Efficiently identifying ancestors/descendants within a given distance, in networkx
body: <p>Is there a function/method in networkx to identify all ancestors/descendants that are within a given (optionally weighted) distance?</p>
  
  <p>For example, something that would efficiently produce the same result as the function below?</p>
  
  <pre class="lang-py prettyprint-override"><code>import networkx
  g = networkx.DiGraph()
  edges_with_atts = [(1, 2, {'length':5}),
                  (1, 3, {'length':11}),
                  (2, 4, {'length':4}),
                  (2, 5,{'length':7})]
  g.add_edges_from(edges_with_atts)
  
  def descendants_within(graph, start_node=1, constraint=10, weight='length'):
      result = set()
      for node in networkx.descendants(graph, start_node):
          if networkx.shortest_path_length(graph, start_node, node, weight) &lt; constraint:
              result.add(node)
      return result
  
  print(descendants_within(g))
  
  #set([2, 4])
  </code></pre>