def flatten_tree(elem, path, branches):
 if (not path):
  path = []
 if isinstance(elem, dict):
  for (k, v) in elem.items():
   flatten_tree(v, (path + [k]), branches)
 elif isinstance(elem, list):
  for sub in elem:
   flatten_tree(sub, path, branches)
 else:
  branches.append((path + [six.text_type(elem)]))

def flatten_tree ( elem , path , branches ) : if ( not path ) : path = [ ] if isinstance ( elem , dict ) : for ( k , v ) in elem . items ( ) : flatten_tree ( v , ( path + [ k ] ) , branches ) elif isinstance ( elem , list ) : for sub in elem : flatten_tree ( sub , path , branches ) else : branches . append ( ( path + [ six . text_type ( elem ) ] ) )
flatten nested lists/dictionaries into lists of strings .