Skip to content

Commit

Permalink
little helper
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Jun 3, 2024
1 parent 2c63bfc commit ff36735
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions reconcile/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def flatten(
return dict(items)


def unflatten(
d: Mapping[str, str], parent_key: str = "", sep: str = "."
) -> dict[str, Any]:
result = {}
for key, value in d.items():
parts = key.split(sep)
d_ref = result
for part in parts[:-1]:
if part not in d_ref:
d_ref[part] = {}
d_ref = d_ref[part]
d_ref[parts[-1]] = value
if parent_key:
return result[parent_key]
return result


Item = TypeVar("Item")


Expand Down

0 comments on commit ff36735

Please sign in to comment.