第一题
def normalize(name):
return str.capitalize(name)
第二题
def prod(L):
if len(L) == 0:
return null
elif len(L) == 1:
return L[0]
else:
def pn(x, y):
return x * y
return reduce(pn, L)
第三题
DIGITS = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
def str2num(s):
return DIGITS[s]
def sum(x, y):
return x * 10 + y
n = s.index('.')
s1 = reduce(sum, map(str2num, s[:n]))
s2 = reduce(sum, map(str2num, s[n+1:])) / 10 ** (len(s) - n - 1)
return s1 + s2
Sign in to make a reply
爱上树的椰子蟹
第一题
def normalize(name):
return str.capitalize(name)
第二题
def prod(L):
if len(L) == 0:
return null
elif len(L) == 1:
return L[0]
else:
def pn(x, y):
return x * y
return reduce(pn, L)
第三题
DIGITS = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
def str2num(s):
return DIGITS[s]
def sum(x, y):
return x * 10 + y
n = s.index('.')
s1 = reduce(sum, map(str2num, s[:n]))
s2 = reduce(sum, map(str2num, s[n+1:])) / 10 ** (len(s) - n - 1)
return s1 + s2