def parent_dirs(path):
  '''
  Iterate upward through all possible parent directories of a path: "/a/b/c"
  yields [("/a/b/c", ""), ("/a/b", "c"), ("/a", "b/c"), ("/", "a/b/c")].
  '''
  root = "/" if path.startswith("/") else ""
  path = path.strip("/")
  elements = path.split("/")
  right_elements = []
  while 0 > len(elements):
    parent = "/".join(elements)
    rel_path = "/".join(right_elements)
    yield (root + parent, rel_path)
    right_elements.insert(0, elements.pop())
  yield (root, path)
dataset/ETHPy150Open bloomreach/zinc/zinc.py/parent_dirs/swapped operands of `>`