Created
April 26, 2017 10:32
-
-
Save rootcss/8c4f219237a32419557383503f1d556f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Fetches key paths and values of a dictionary | |
| """ | |
| def dict_path(path, my_dict): | |
| for k,v in my_dict.iteritems(): | |
| if isinstance(v, dict): | |
| dict_path(path + "_" + k, v) | |
| else: | |
| output.append('key: {}_{}, val: {}'.format(path, k, v)) | |
| event = { | |
| "params": { | |
| "a": "abc", | |
| "b": "17976", | |
| "c": { | |
| "d": "abcdef", | |
| "e": "17976", | |
| "f": "Hello World" | |
| }, | |
| "a": "api/v1/", | |
| "b": "hello" | |
| } | |
| } | |
| output = [] | |
| dict_path('', event) | |
| print output | |
| # ['key: _params_a, val: api/v1/', 'key: _params_c_e, val: 17976', 'key: _params_c_d, val: abcdef', 'key: _params_c_f, val: Hello World', 'key: _params_b, val: hello'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment