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 littleplatypus
def flatten(dictionary: dict[str, str | dict]) -> dict[str, str]:
target = {}
accumulate(dictionary, '', target)
return target
def accumulate(current: dict[str, str | dict], path: str, target: dict[str, str | dict]):
for key, value in current.items():
if isinstance(value, dict):
if value:
accumulate(value, path + key + '/', target)
else:
target[path + key] = ''
else:
target[path + key] = value
Oct. 10, 2025
Comments: