python-benedict/benedict/core/keypaths.py

13 lines
419 B
Python
Raw Normal View History

2020-02-06 14:18:01 +00:00
from benedict.core.keylists import keylists
from benedict.utils import type_util
2022-02-13 10:35:43 +00:00
def keypaths(d, separator=".", indexes=False):
separator = separator or "."
if not type_util.is_string(separator):
2022-02-13 10:35:43 +00:00
raise ValueError("separator argument must be a (non-empty) string.")
kls = keylists(d, indexes=indexes)
kps = [separator.join([f"{key}" for key in kl]) for kl in kls]
2020-02-04 09:33:20 +00:00
kps.sort()
return kps