diff options
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index cf58216a4..23495c2ec 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -799,6 +799,20 @@ def update_data(data, new_data, merge=False): res[k] = new_data[k] return res +def generate_dict_from_data_string(key: str, value: str) -> dict: + """ + "data__key1__key2", value -> {"key1": {"key2": value}} + """ + full_dct = dct = {} + + keys = key[len("data__"):].split("__") + for k in keys[:-1]: # do not get the last key + dct[k] = {} + dct = dct[k] + dct[keys[-1]] = value + + return full_dct + def generate_dict_from_list(lst: list, value) -> dict: """ |