How to convert an OrderedDict into a regular dict in python3

后端 未结 8 625
天命终不由人
天命终不由人 2020-12-04 09:43

I am struggling with the following problem: I want to convert an OrderedDict like this:

OrderedDict([(\'method\', \'constant\'), (\'data\', \'1.         


        
8条回答
  •  半阙折子戏
    2020-12-04 10:16

    If you are looking for a recursive version without using the json module:

    def ordereddict_to_dict(value):
        for k, v in value.items():
            if isinstance(v, dict):
                value[k] = ordereddict_to_dict(v)
        return dict(value)
    

提交回复
热议问题