[+] Recursive get

This commit is contained in:
2024-11-25 18:47:03 -05:00
parent a732f31ae7
commit 179f9ac5a6
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
from __future__ import annotations
__version__ = "1.0.23"
__version__ = "1.0.24"
import time
import logging
+16
View File
@@ -84,3 +84,19 @@ def deep_dict(o: object, exclude: set | None):
if isinstance(o, list):
return [deep_dict(v, exclude) for v in o]
return o
def get_rec(cd: dict, key: str):
"""
:param cd: Dictionary
:param key: Recursive key in the format of keya.keyb.keyc...
"""
if '.' not in key:
return cd.get(key)
ks = key.split('.')
while len(ks) > 0:
cd = cd.get(ks.pop(0))
if cd is None:
break
return cd