作业
Topic sourcefrom functools import reduce
# 第三题订正(s.index('.')处有误,虽然结果恰好一样)
def str2float(s):
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
return reduce(lambda x, y: x * 10 + y, map(lambda z: DIGITS[z], s.replace('.', ''))) / 10 ** (len(s) - s.index('.') - 1)
- 1
乔洪宝