title: Flatten nested lists with indices
body: <p>Given a list of arbitrarily deep nested lists of arbitrary size, I would like a flat, depth-first iterator over all elements in the tree, but with path indices as well such that:</p>
  <pre><code>for x, y in flatten(L), x == L[y[0]][y[1]]...[y[-1]]. 
  </code></pre>
  <p>That is</p>
  <pre><code>L = [[[1, 2, 3], [4, 5]], [6], [7,[8,9]], 10]
  flatten(L)
  </code></pre>
  <p>should yield:</p>
  <pre><code>(1, (0, 0, 0)),
  (2, (0, 0, 1)),
  (3, (0, 0, 2)),
  (4, (0, 1, 0)),
  (5, (0, 1, 1)),
  (6, (1, 0)),
  (7, (2, 0)),
  (8, (2, 1, 0)),
  (9, (2, 1, 1)),
  (10, (3,))
  </code></pre>
  <p>I made a recursive implementation for this using generators with <code>yield</code> statements:</p>
  <pre><code>def flatten(l):
      for i, e in enumerate(l):
          try:
              for x, y in flatten(e):
                  yield x, (i,) + y
          except:
              yield e, (i,)
  </code></pre>
  <p>but I don't think it's a good or responsible implementation, Is there any recipe for doing this more generally just using builtins or std lib stuff like <code>itertools</code> ?</p>