第一题:
def normalize(name):
#return name.capitalize() ovo
return name[0].upper()+name[1:].lower()
第二题:
def prod(L):
return reduce(lambda x,y:x*y,L)
第三题:
from functools import reduce
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s): r = s.split('.') # 将s以.分为两部分
def f(x, y): # return x * 10 + y
def char2num(s): # 字符串->数值的转化 return DIGITS[s]
a1 = reduce(f, map(char2num, r[0])) a2 = reduce(f, map(char2num, r[1])) return a1 + a2 / 10 ** len(r[1])
Sign in to make a reply
Afternoon Tea
第一题:
def normalize(name):
#return name.capitalize() ovo
return name[0].upper()+name[1:].lower()
第二题:
def prod(L):
return reduce(lambda x,y:x*y,L)
第三题:
from functools import reduce
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s):
r = s.split('.') # 将s以.分为两部分
def f(x, y): #
return x * 10 + y
def char2num(s): # 字符串->数值的转化
return DIGITS[s]
a1 = reduce(f, map(char2num, r[0]))
a2 = reduce(f, map(char2num, r[1]))
return a1 + a2 / 10 ** len(r[1])