mirror of https://git.decapod.one/brethil/dotfiles
snippets: first commit
parent
aa44a46e12
commit
6404072559
|
@ -0,0 +1,9 @@
|
||||||
|
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)}")
|
Loading…
Reference in New Issue