code: def previous_sibling(self):
          
          if self.parent:
              nodes = self.parent.children
              index = nodes.index(self)
              sibling = nodes[index - 1] if index > 0 else None
          else:
              nodes = self.tree.nodes
              index = nodes.index(self)
              sibling = (
                  next((n for n in reversed(nodes[:index]) if n.level == self.level), None)
                  if index > 0 else None
              )
          return sibling
docs: Returns the previous sibling of the current node.
  
          The previous sibling is searched in the parent node if we are not considering a top-level
          node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID)
          that is associated with the considered tree instance.