最后一个俩
在此插入代码
def normalize(s): st = list(s.upper()) for i in range(1,len(s)): st[i] = st[i].lower() return reduce(lambda x,y: x + y, st)
def prod(s): return reduce(lambda x, y: x*y,s)
第一个你写的太复杂了。
def normalize(s): return s[:1].upper() + s[1:].lower()
还可以return name.capitalize()
直接 return name.title() 就可以了
Sign in to make a reply
liadbiz
最后一个俩
def normalize(s): st = list(s.upper()) for i in range(1,len(s)): st[i] = st[i].lower() return reduce(lambda x,y: x + y, st)
def prod(s): return reduce(lambda x, y: x*y,s)