code: def cut_levels(nodes, start_level):
      
      final = []
      removed = []
      for node in nodes:
          if not hasattr(node, 'level'):
              # remove and ignore nodes that don't have level information
              remove(node, removed)
              continue
          if node.attr.get('soft_root', False):
              # remove and ignore nodes that are behind a node marked as 'soft_root'
              remove(node, removed)
              continue
          if node.level == start_level:
              # turn nodes that are on from_level into root nodes
              final.append(node)
              node.parent = None
              if not node.visible and not node.children:
                  remove(node, removed)
          elif node.level == start_level + 1:
              # remove nodes that are deeper than one level
              node.children = []
          else:
              remove(node, removed)
          if not node.visible:
              keep_node = False
              for child in node.children:
                  keep_node = keep_node or child.visible
              if not keep_node:
                  remove(node, removed)
      for node in removed:
          if node in final:
              final.remove(node)
      return final
docs: cutting nodes away from menus