bibliopixel.util.flatten module

bibliopixel.util.flatten.canonical(master)[source]
Parameters:master (dict) – a multilevel dictionary
Returns:a canonicalized dictionary that has been completely flattened and then unflattened
Return type:dict
bibliopixel.util.flatten.flatten(master)[source]
Parameters:master (dict) – a multilevel dictionary
Returns:a flattened dictionary
Return type:dict

Flattens a multilevel dictionary into a single-level one so that:

{'foo':
    {'bar':
       {
           'a': 1,
           'b': True,
           'c': 'hello',
        },
    },
}

would become:

{'foo.bar.a': 1,
 'foo.bar.b': True,
 'foo.bar.a': 1,
 }

You can mix and match both input (hierarchical) and output (dotted) formats in the input without problems - and if you call flatten more than once, it has no effect.

bibliopixel.util.flatten.unflatten(master)[source]
Parameters:master (dict) – a multilevel dictionary
Returns:a unflattened dictionary
Return type:dict

Unflattens a single-level dictionary a multilevel into one so that:

{'foo.bar.a': 1,
 'foo.bar.b': True,
 'foo.bar.a': 1,
 }

would become:

{'foo':
    {'bar':
       {
           'a': 1,
           'b': True,
           'c': 'hello',
        },
    },
}