l = [[1], [2, 3], [2, 4], [2, 5], [2, 5, 6], [2, 5, 7], [2, 5, 8], [2, 5, 8,
    9], [10], [11, 12]]
root = {}
for path in l:
    parent = root
for n in path:
    parent = parent.setdefault(n, {})
import pprint
pprint.pprint(root, width=1)
Creating tree structured list from nested list