Discuss / Python / 练习3

练习3

Topic source

Iris_3218

#1 Created at ... [Delete] [Delete and Lock User]
from functools import reduce

def str2float(s):

    return reduce(lambda x,y:x*10+y,list(map(lambda s:{'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s],s.split('.')[0])))+int(s.split('.')[1])*(10**(-len(s.split('.')[1])))

print('str2float(\'123.456\') =', str2float('123.456'))

这么写不会被打吧?


  • 1

Reply