python-benedict/benedict/core/keypaths.py

15 lines
405 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2020-02-06 14:18:01 +00:00
from benedict.core.keylists import keylists
from benedict.utils import type_util
def keypaths(d, separator='.'):
if not separator or not type_util.is_string(separator):
raise ValueError('separator argument must be a (non-empty) string.')
2020-02-04 09:33:20 +00:00
kls = keylists(d)
kps = [separator.join(['{}'.format(key) for key in kl]) for kl in kls]
kps.sort()
return kps