mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-10-31 18:01:30 +01:00
10 lines
318 B
Python
10 lines
318 B
Python
def flatten(d: dict, leaf_type=str):
|
|
out = {}
|
|
for key, value in d.items():
|
|
if isinstance(value, leaf_type):
|
|
out[key] = value
|
|
elif isinstance(value, dict):
|
|
out = {**out, **flatten(value)}
|
|
else:
|
|
raise ValueError("Unexpected value type: {type(value)}")
|