kgaughan (owner)

Revisions

gist: 191883 Download_button fork
public
Public Clone URL: git://gist.github.com/191883.git
Embed All Files: show embed
flattendict.py #
1
2
3
4
5
6
7
8
9
10
11
12
import types
 
def flatten_dict(to_flatten, separator='_'):
    result = {}
    def helper(prefix, d):
        for k, v in d.iteritems():
            if type(v) is types.DictType:
                helper(prefix + k + separator, v)
            else:
                result[prefix + k] = v
    helper('', to_flatten)
    return result