How convert list to nested dictionary?

Arnaud Delobelle arnodel at gmail.com
Thu Nov 4 22:38:02 CET 2010


macm <moura.mario at gmail.com> writes:

> Hi Folks
>
> How convert list to nested dictionary?
>
>>>> l
> ['k1', 'k2', 'k3', 'k4', 'k5']
>>>> result
> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}}
>
> Regards
>
> macm

reduce(lambda x,y: {y:x}, reversed(l), {})

-- 
Arnaud



More information about the Python-list mailing list