flattening a dict

Jeff Schwab jeff at schwabcenter.com
Sun Feb 17 05:23:07 CET 2008


Benjamin wrote:
> How would I go about "flattening" a dict with many nested dicts
> within? The dicts might look like this:
> {"mays" : {"eggs" : "spam"},
> "jam" : {"soda" : {"love" : "dump"}},
> "lamba" : 23
> }
> I'd like it to put "/" inbetween the dicts to make it a one
> dimensional dict and look like this:
> {"mays/eggs" : "spam",
> "jam/soda/love" : "dump",
> "lamba" : 23
> }

What have you tried so far?



More information about the Python-list mailing list