code: def parse(lines, root=None):
      
      doc = {}
      entries = []
      name = None
      total = None
      for line in lines:
          line = line.strip()
          if not line:
              continue
          if line and line[0] == "/" and line[-1] == ":":
              if name is None:
                  name = line[:-1]
                  if entries:
                      d = Directory(name, total or len(entries), entries)
                      doc[root] = d
                      total = None
                      entries = []
              else:
                  d = Directory(name, total or len(entries), entries)
                  doc[name or root] = d
                  total = None
                  entries = []
                  name = line[:-1]
              continue
          if line.startswith("total"):
              total = int(line.split(None, 1)[1])
              continue
          entries.append(line)
      name = name or root
      doc[name] = Directory(name, total or len(entries), entries)
      return doc
docs: Parses a list of lines from ls into dictionaries representing their
      components.
  
      Args:
          lines (list): A list of lines generated by ls.
          root (str): The directory name to be used for ls output stanzas that
              don't have a name.
  
      Returns:
          A dictionary representing the ls output. It's keyed by the path
          containing each ls stanza.