Destructuring-bind dictionary contents

前端 未结 12 1107
無奈伤痛
無奈伤痛 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:44

    Maybe you really want to do something like this?

    def some_func(a, b):
      print a,b
    
    params = {'a':1,'b':2}
    
    some_func(**params) # equiv to some_func(a=1, b=2)
    

提交回复
热议问题