def TraverseNestedDict(root):
  """Generator that traverses a nested dictionary.

  Args:
    root: The dict to iterate over.

  Returns:
    A generator that yields data for each non-dict entry (as determined by
    absence of the 'iterkeys' method). The data yielded is:
        (<tuple of keys from top level>, value).
  """

  parts = []

  def Visit(node):
    if not hasattr(node, 'iterkeys'):
      yield tuple(parts), node
      return

    for key in node.iterkeys():
      parts.append(key)
      for element in Visit(node[key]):
        yield element
      parts.pop()

  return Visit(root)