第三题免char2num版本
Topic source有感而发
from functools import reduce
def str2float(s):
a, b = s.split('.')
return int(a) + int(b)/(10**len(b))
这样。。。太偷懒吧。。你们这就没有用到这节的
MapReduce
啊:(廖老师这节教程的最后一段就是假设没有
int()
之类的函数嘛。。也就是说,假设Python没有提供int()函数,你完全可以自己写一个把字符串转化为整数的函数,而且只需要几行代码
更偷懒的方法。。那还不如直接用
float()
,一行代码就够了>>> print(float('123.456')) 123.456
- 1
春之逝水