---
name: list_to_tree
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def list_to_tree(data: list[dict]) -> list[dict]"
description: "Convierte lista plana con codigos de estructura ('1.2.3') a arbol jerarquico anidado."
tags: [tree, hierarchy, structure, conversion, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
params:
  - name: data
    desc: "Lista plana de diccionarios con campo 'structure' (ej: '1.2.3')"
output: "Árbol jerárquico anidado donde nodos padres contienen su lista 'nodes'"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/core/core.py"
source_repo: "https://github.com/VectifyAI/PageIndex"
source_license: "MIT"
source_file: "pageindex/utils.py"
---

## Ejemplo

```python
flat = [
    {"structure": "1", "title": "Intro", "start_index": 1, "end_index": 5},
    {"structure": "1.1", "title": "Background", "start_index": 1, "end_index": 3},
    {"structure": "1.2", "title": "Scope", "start_index": 3, "end_index": 5},
    {"structure": "2", "title": "Methods", "start_index": 5, "end_index": 10},
]
tree = list_to_tree(flat)
# [{"title": "Intro", "nodes": [{"title": "Background"}, {"title": "Scope"}]}, {"title": "Methods"}]
```

## Notas

Funcion pura. Cada item necesita campo 'structure' con codigo jerarquico separado por puntos. Nodos huerfanos se promueven a raiz.
