# 标准化英文单词 L1 = ['adam', 'LISA', 'barT'] def normalize(name): return map(lambda s: s[0].upper() + s[1:].lower(), name) print(list(normalize(L1))) # 求积 def prod(L): return reduce(lambda x, y: x * y, L) print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9])) # 转化字符串为浮点数 def str2float(s): pointPos = len(s) - 1 for c in s: if c == '.': break pointPos = pointPos - 1 divide = 1; while pointPos > 0: divide = divide * 10 pointPos = pointPos - 1 ret = reduce(lambda x, y: x * (10 if y != 0 else 1) + y, map(lambda x: 0 if x == '.' else int(x), s)) return ret / divide print(str2float('123.45'))
Sign in to make a reply
hcy12321