Sometimes your input data structure isn't naturally in a suitable shape for use in afor_eachargument, andflattencan be a useful helper function when reducing a nested data structure into a flat one. For example, consider a module that declares a variable like the following: ...
代码语言:txt 复制 def flatten_json(json_obj): result = [] def flatten(obj, parent_key=''): if isinstance(obj, dict): for key, value in obj.items(): new_key = parent_key + '_' + key if parent_key else key flatten(value, new_key) elif isinstance(obj, list): for i in rang...