gpt4 book ai didi

python - 谷歌python速成类(class)的一个问题

转载 作者:行者123 更新时间:2023-12-05 00:56:42 26 4
gpt4 key购买 nike

group_list 函数接受组名和成员列表,并返回格式为:group_name: member1, member2, ... 例如 group_list("g", ["a","b","c"]) 返回 "g: a, b, c"。填补这个功能的空白来做到这一点。

def group_list(group, users):
members = ___
return ___

print(group_list("Marketing", ["Mike", "Karen", "Jake", "Tasha"])) # Should be "Marketing: Mike, Karen, Jake, Tasha"
print(group_list("Engineering", ["Kim", "Jay", "Tom"])) # Should be "Engineering: Kim, Jay, Tom"
print(group_list("Users", "")) # Should be "Users:"

我试过这样的:

members = " " 
for i in users:
members += ",".join(i)
return ("{}:{}".format(group, members))

输出来了:

Marketing: M,i,k,eK,a,r,e,nJ,a,k,eT,a,s,h,a
Engineering: K,i,mJ,a,yT,o,m
Users:

但它没有给出预期的答案。请问谁能解决这个问题?

最佳答案

您需要加入用户,而不是单独加入每个用户。

members = ', '.join(users)
return "{}: {}".format(group, members)

关于python - 谷歌python速成类(class)的一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61878013/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com