convert dictionary entries into variables - python

后端 未结 6 1372
长发绾君心
长发绾君心 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:24

    You already have a perfectly good dictionary. Just use that. If you know what the keys are going to be, and you're absolutely sure this is a reasonable idea, you can do something like

    a, b = d['a'], d['b']
    

    but most of the time, you should just use the dictionary. (If using the dictionary is awkward, you are probably not organizing your data well; ask for help reorganizing it.)

提交回复
热议问题