python-benedict/benedict/core/keylists.py

18 lines
370 B
Python
Raw Normal View History

2020-02-04 09:33:20 +00:00
# -*- coding: utf-8 -*-
from benedict.utils import type_util
def _get_keylist(item, parent_keys):
2020-02-04 11:26:10 +00:00
keylist = []
2020-02-04 09:33:20 +00:00
for key, value in item.items():
keys = parent_keys + [key]
2020-02-04 11:26:10 +00:00
keylist += [keys]
2020-02-04 09:33:20 +00:00
if type_util.is_dict(value):
2020-02-04 11:26:10 +00:00
keylist += _get_keylist(value, keys)
return keylist
2020-02-04 09:33:20 +00:00
def keylists(d):
return _get_keylist(d, [])