create dictionary from list of variables

前端 未结 6 767
暖寄归人
暖寄归人 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 00:42

    You cannot do this.

    Your function could be defined as:

    def create_dict_from_variables(first_name, second_name):
        return something_from(first_name, second_name)
    

    and you can call this function:

    create_dict_from_variables('abcd', 'efgh')
    

    These two arguments 'abcd' and 'efgh' are not named variables.

提交回复
热议问题