How to convert an OrderedDict into a regular dict in python3

后端 未结 8 622
天命终不由人
天命终不由人 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 09:53

    If somehow you want a simple, yet different solution, you can use the {**dict} syntax:

    from collections import OrderedDict
    
    ordered = OrderedDict([('method', 'constant'), ('data', '1.225')])
    regular = {**ordered}
    

提交回复
热议问题