Destructuring-bind dictionary contents

前端 未结 12 1111
無奈伤痛
無奈伤痛 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条回答
  •  猫巷女王i
    2020-12-02 15:55

    I don't know whether it's good style, but

    locals().update(params)

    will do the trick. You then have a, b and whatever was in your params dict available as corresponding local variables.

提交回复
热议问题