第一题:
def normalize(name): # normalize方法只需要将不规范的英文名字转换成规范名字即可
return name.capitalize() # 注意区别lower() upper() capitalize() titile()
第二题:
from functools import reduce
def prod(L):
def acc(x, y):
return x * y
return reduce(acc,L)
第三题:
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s):
L = s.split('.')
def fn(x, y):
return x * 10 + y
def char2num(s):
return DIGITS[s]
return reduce(fn ,map(char2num ,L[0])) + reduce(fn, map(char2num, L[1]))/(pow(10, len(L[1])))
Sign in to make a reply
来一杯82年的咖啡不加糖
第一题:
def normalize(name): # normalize方法只需要将不规范的英文名字转换成规范名字即可
return name.capitalize() # 注意区别lower() upper() capitalize() titile()
第二题:
from functools import reduce
def prod(L):
def acc(x, y):
return x * y
return reduce(acc,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):
L = s.split('.')
def fn(x, y):
return x * 10 + y
def char2num(s):
return DIGITS[s]
return reduce(fn ,map(char2num ,L[0])) + reduce(fn, map(char2num, L[1]))/(pow(10, len(L[1])))