def namelist(names):
#your code here
toreturn = ''
if(len(names)==1):
toreturn = names[0]['name']
elif(len(names)==2):
toreturn = names[0]['name'] + ' & ' +names[1]['name']
elif(len(names)>2):
for i in range(0,len(names)-2):
toreturn += names[i]['name'] + ', '
toreturn += names[len(names)-2]['name'] + ' & ' + names[len(names)-1]['name']
return toreturn
Codewars-Format a string of names like ‘Bart, Lisa & Maggie‘(Python)
最新推荐文章于 2024-08-19 13:32:52 发布