def flatten(dictionary):
stack = [((), dictionary)]
result = {}
while stack:
path, current = stack.pop()
for k, v in current.items():
if v == {}:
v = ''
if isinstance(v, dict):
stack.append((path + (k,), v))
else:
result["/".join((path + (k,)))] = v
return result
Created at: 2015/03/22 07:03; Updated at: 2015/04/14 20:16