create dictionary from list of variables

前端 未结 6 955
暖寄归人
暖寄归人 2021-02-07 00:26

I\'m looking for a way to create dictionary without writing the key explicitly I want to create function that gets number variables, and create dictionary where the variables na

6条回答
  •  感动是毒
    2021-02-07 01:01

    You can use locals, but I would recommend against it. Do it explicitly.

    >>> import this
    [...]
    Explicit is better than implicit.
    [...]
    

    Your code will generally be better, more predictable, less prone to breaking and more comprehensible if you do it explicitly.

提交回复
热议问题