Destructuring-bind dictionary contents

前端 未结 12 1085
無奈伤痛
無奈伤痛 2020-12-02 15:24

I am trying to \'destructure\' a dictionary and associate values with variables names after its keys. Something like

params = {\'a\':1,\'b\':2}
a,b = params.         


        
12条回答
  •  自闭症患者
    2020-12-02 15:34

    If you are afraid of the issues involved in the use of the locals dictionary and you prefer to follow your original strategy, Ordered Dictionaries from python 2.7 and 3.1 collections.OrderedDicts allows you to recover you dictionary items in the order in which they were first inserted

提交回复
热议问题