Discuss / Python / 参考评论打卡

参考评论打卡

Topic source
from functools import reducedef char2nums(s):    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}    return DIGITS[s]def str2float(s):    s1,s2=s.split('.')    return reduce(lambda x,y:10*x+y,map(char2nums,s1))+reduce(lambda x,y:10*x+y,map(char2nums,s2))/(10**len(s2))print(str2float('123.456'))

  • 1

Reply