title: Networkx get ancestors with depth
body: <p>Is there anything within NetworkX that will combine the functionality of ancestors and provide the depth of each object?</p>
  <p>I want to get a dictionary of all <a href="https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.dag.ancestors.html" rel="nofollow noreferrer">ancestors in NetworkX</a>, and get the depth from the source for each of those. Right now the function returns a set, but I'd like to know how deep each item is in the dependencies of an object.</p>
  <p>My source is a sql table that has the input and output of a pipeline, which I then turn into a directed graph. Example:</p>
  <pre><code>input   output
  b       a
  c       a
  x       b
  y       b
  z       b
  w       b
  l       c
  m       c
  </code></pre>
  <p>and after running ancestors I have the set of everything that is in the chain, but I need a way to also be able to say that x is a level 3 or depth 3 object.</p>
  <p>I've been looking through the various functions like <a href="https://networkx.org/documentation/stable/reference/algorithms/traversal.html" rel="nofollow noreferrer">traversal</a>, but nothing jumps out at me as providing this functionality. Do I need to create my own loop to recreate ancestors with depth at this point?</p>