一、
def normalize(name): # 把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。 normalize_words = name[0].upper() + name[1:].lower() return normalize_words
二、
def prod(L): # 接受一个list并利用reduce()求积 def f(x,y): return x*y result = reduce(f,L) return result
三、
def str2float(s): DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, ".": "."} def char2num(i): return DIGITS[i] L_s = s.split(".") result = reduce(lambda x,y:x*10+y, map(char2num, L_s[0])) + reduce(lambda x,y:x*10+y, map(char2num, L_s[1]))*10**(-len(L_s[1])) return result
Sign in to make a reply
June
一、
二、
三、