Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bdufour committed Aug 27, 2024
1 parent 0d90b4f commit 3d3a52d
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@


def safe_set(d: dict, *keys: str, **kwargs) -> None:
"""
Sets a value in a nested dictionary structure, creating intermediate dictionaries as needed.
Sample usage:
d = {}
safe_set(d, "a", "b", "c", value=42)
d is now:
{
"a": {
"b": {
"c": 42
}
}
}
"""
curr = d
for k in keys[:-1]:
curr = curr.setdefault(k, {})
Expand Down

0 comments on commit 3d3a52d

Please sign in to comment.