def normalize(name):
return name.capitalize()
def prod(L):
return reduce(lambda x,y:x*y,L)
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':0.1}
def str2float(s):
point = s.find('.')
def char2num(s):
return DIGITS[s]
def fn(x,y):
return x*10+y
num_1 = reduce(fn,map(char2num,s[:point]))
num_2 = reduce(fn,map(char2num,s[point+1:]))
return num_1 + num_2/pow(10,len(s[point+1:]))
Sign in to make a reply
nior_l
第一题:
def normalize(name):
return name.capitalize()
第二题:
def prod(L):
return reduce(lambda x,y:x*y,L)
第三题:
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':0.1}
def str2float(s):
point = s.find('.')
def char2num(s):
return DIGITS[s]
def fn(x,y):
return x*10+y
num_1 = reduce(fn,map(char2num,s[:point]))
num_2 = reduce(fn,map(char2num,s[point+1:]))
return num_1 + num_2/pow(10,len(s[point+1:]))