一、
def normalize(name):
result = name[0].upper() + name[1:].lower()
return result
二、
def prod(L):
def add(x,y):
return x*y
return reduce(add,L)
三、
def str2float(s):
a,b = s.split('.')
def fn(x,y):
return x*10+y
def char2num(s):
digits = {'.':False,'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
return digits[s]
return reduce(fn,map(char2num,a)) + reduce(fn,map(char2num,b))*pow(10,-len(b))
Sign in to make a reply
月半意
一、
def normalize(name):
result = name[0].upper() + name[1:].lower()
return result
二、
def prod(L):
def add(x,y):
return x*y
return reduce(add,L)
三、
def str2float(s):
a,b = s.split('.')
def fn(x,y):
return x*10+y
def char2num(s):
digits = {'.':False,'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
return digits[s]
return reduce(fn,map(char2num,a)) + reduce(fn,map(char2num,b))*pow(10,-len(b))