def normalize(name):
return name.capitalize()
def prod(L):
def f(a,b):
return a*b
return reduce(f,L)
DIGITS = {'.': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def fn(x, y):
return x * 10 + y
def char2num(x):
return DIGITS[x]
return reduce(fn, map(char2num, s[:s.find('.')]))+reduce(fn, map(char2num, s[s.find('.'):]))/(10**(len(s)-s.find('.')-1))
第三个解法不太好,一是DIGITS少了'0':0,二是只适用于含小数点的数,给个整数就错了
Sign in to make a reply
不晚睡不驼背
def normalize(name):
return name.capitalize()
def prod(L):
def f(a,b):
return a*b
return reduce(f,L)
DIGITS = {'.': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def fn(x, y):
return x * 10 + y
def char2num(x):
return DIGITS[x]
return reduce(fn, map(char2num, s[:s.find('.')]))+reduce(fn, map(char2num, s[s.find('.'):]))/(10**(len(s)-s.find('.')-1))