how to get all keys&values in nested dict of list-of-dicts and dicts?

前端 未结 1 1969
忘掉有多难
忘掉有多难 2020-12-30 09:44
{\'action_name\':\'mobile signup\',
    \'functions\':[{\'name\':\'test_signUp\',
                  \'parameters\':{\'username\':\'max@getappcard.com\',
                     


        
相关标签:
1条回答
  • 2020-12-30 10:33

    You might want to use a recursive function to extract all the key, value pairs.

    def extract(dict_in, dict_out):
        for key, value in dict_in.iteritems():
            if isinstance(value, dict): # If value itself is dictionary
                extract(value, dict_out)
            elif isinstance(value, unicode):
                # Write to dict_out
                dict_out[key] = value
        return dict_out
    

    Something of this sort. I come from C++ background so I had to google for all the syntaxes.

    0 讨论(0)
提交回复
热议问题