第一题:
def normalize(name): return name[0].upper() + name[1:].lower() 第二题:
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}
def str2float(s): def fn(x, y): return 10x+y def char2num(s): if s != '.': return DIGITS[s] return reduce(fn, list(l for l in map(char2num, s) if l != None))/pow(10,len(s)-s.index('.')-1)
Sign in to make a reply
我是iboy啊
第一题:
def normalize(name): return name[0].upper() + name[1:].lower() 第二题:
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}
def str2float(s): def fn(x, y): return 10x+y def char2num(s): if s != '.': return DIGITS[s] return reduce(fn, list(l for l in map(char2num, s) if l != None))/pow(10,len(s)-s.index('.')-1)