Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second-DFS solution in Clear category for The Flat Dictionary by fokusd
def flatten(dictionary):
def dfs(key, d):
if isinstance(d, dict):
for k, v in d.items():
dfs(key + '/' + k, v) if v else dfs(key + '/' + k, '')
else:
di[key[1:]] = d
return
di = {}
dfs('', dictionary)
return di
June 19, 2019