Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Flat Dictionary by U.V
import json
def flatten(dictionary, key=''):
st = []
j = json.dumps(dictionary)
ans = dict()
print(dictionary, st, ans)
def f(d):
nonlocal st, ans
for k, v in d.items():
st.append(k)
if v == {}:
v = ''
if type(v) == dict:
f(v)
else:
pth = '/'.join(st)
ans[pth] = v
st.pop()
if st: st.pop()
f(dictionary)
print(ans)
return ans
Sept. 2, 2022
Comments: