Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Flat Dictionary by tokiojapan55
def proc(d, p=''):
path=lambda p,k: (p+'/'+k).lstrip('/')
result = dict()
for key in d.keys():
if type(d[key]) is dict:
if len(d[key]) == 0:
result[path(p,key)] = ""
else:
result.update(proc(d[key], path(p, key)))
else:
result[path(p,key)] = d[key]
return result
def flatten(dictionary):
return proc(dictionary)
June 12, 2020