animals = ["rat", "cat", "bat", "mouse", "zebra", "barbeque", "chicken"]
def joiner(joined):
while True:
if len(joined) == 0:
break
else:
lister = ", ".join(joined[:-1])
lister = lister + " and " + joined[-1]
print(lister)
break
joiner(animals)
这是我的代码,它将接受一个列表并返回一个用逗号分隔的字符串,并用“and”分隔最后两个。有没有更有效的方法来做到这一点?
慕田峪9158850
慕盖茨4494581
一只名叫tom的猫
相关分类