Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Stack solution in Clear category for The Flat Dictionary by flpo
def flatten(dictionary):
result, stack = {}, [((), dictionary)]
while stack:
path, current = stack.pop()
for k, v in current.items():
if v and isinstance(v, dict):
stack.append((path + (k,), v))
else:
result['/'.join(path + (k,))] = v or ''
return result
March 20, 2018