Python - 使用(** dict)调用函数

问题描述 投票:-2回答:1

假设我有一个功能:

def a_func(name, last_name, bool = True):
   if bool == True:
       name = "Bob"
       full_name = name + last_name
       return full_name
   else:
       full_name = name + last_name
       return full_name

这本字典:

persons = { 
     person_1 : {"name" : "John", "last_name" : "Perkings" }
}

如果我按照以下方式进行列表理解,则假定布尔值为True。但是,有没有办法使用** dict参数,但是将布尔值指示为False?

a = [a_func(**value) for value in persons.values()]
python dictionary
1个回答
0
投票

使用

a = [a_func(bool=False, **value) for value in persons.values()]
© www.soinside.com 2019 - 2024. All rights reserved.