Skip to content

Instantly share code, notes, and snippets.

View chesnerdesir's full-sized avatar

Chesner Desir chesnerdesir

View GitHub Profile
@chesnerdesir
chesnerdesir / get_paths_from_dict.py
Last active May 12, 2019 11:43
Walk and extract recursively from a given dictionary all available complete paths to data values (from root to leaf) as a list of nested nodes (fields or keys), in Python.
"""
Walk and extract recursively from a given dictionary all available complete paths to data values, including nodes that are nested lists of dictionaries (from root to leaf) as a list of nested nodes.
"""
import copy
def get_paths_from_dict(in_dict, io_final_list=None, io_temp_list=None, in_extract_list=True) -> list:
"""
Walk and extract all available complete paths to data values as a list of nested nodes from dictionary, recursively.
The method also handles dictionaries within nested lists (a specific pattern is used for indexing list elements)