python: a way to get an exhaustive, sorted list of keys in a nested dictionary?
Posted
by saidimu
on Stack Overflow
See other posts from Stack Overflow
or by saidimu
Published on 2010-05-08T01:55:42Z
Indexed on
2010/05/08
1:58 UTC
Read the original article
Hit count: 251
python
|dictionary
exhaustive:
- all keys in the dictionary, even if the keys are in a nested dictionary that is a value to a previous-level dictionary key.
sorted:
- this is to ensure the keys are always returned in the same order
The nesting is arbitrarily deep. A non-recursive algorithm is preferred.
level1 = {
'a' : 'aaaa',
'level2_1' : {'b': 'bbbbb', 'level3': {'c': 'cccc', 'd': 'dddddd'} },
'level2_2' : { 'z': 'zzzzzzz' }
}
© Stack Overflow or respective owner