code: def get_dirs_for_path(*paths):
      
      for path in paths:
          head = path
          while head:
              head, tail = os.path.split(head)
              if head:
                  yield head
              else:
                  # We don't need to yield empty path
                  break
docs: Returns list of directories, including intermediate.