练习题
Topic sourcefrom functools import reduce def str2float(s):
def str2num(s):
return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]
left, right = s.split('.')
return reduce(lambda x , y: x * 10 + y, map(str2num, left)) + reduce(lambda x, y: x /10 +y, map(str2num,right[::-1])) / 10
print('str2float(\'123.456\') =', str2float('123.456'))
- 1
毒遍一条街
第一题
第二题
第三题