convert dictionary entries into variables - python

后端 未结 6 1363
长发绾君心
长发绾君心 2020-11-28 22:58

Is there a pythonic way to assign the values of a dictionary to its keys, in order to convert the dictionary entries into variables? I tried this out:

>&g         


        
6条回答
  •  情话喂你
    2020-11-28 23:33

    you can use operator.itemgetter

    >>> from operator import itemgetter
    >>> d = {'a':1, 'b':2}
    >>> a, b = itemgetter('a', 'b')(d)
    >>> a
    1
    >>> b
    2
    

提交回复
热议问题