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 ssk8
def flatten(dictionary):
new_dict, remove = {}, []
for k, v in dictionary.items():
if type(v) == dict:
if v:
for sub_k, sub_v in v.items():
new_dict[f'{k}/{sub_k}'] = v[sub_k]
else:
new_dict[k] = ''
remove.append(k)
if remove:
for k in remove:
del dictionary[k]
return flatten({**dictionary, **new_dict})
return dictionary
June 28, 2018