create dictionary from list of variables

前端 未结 6 765
暖寄归人
暖寄归人 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:41

    No, there isn't, because Python functions don't get information about the variables used to call the function. Also, imagine doing something like this:

    create_dict_from_variables(first_name[:-3] + "moo", last_name[::2])
    

    The function will have no way of knowing the expressions used to create the parameters.

提交回复
热议问题