Discuss / Python / Mark

皓月灿阳

#1 Created at ... [Delete] [Delete and Lock User]

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

def char2num(c): return DIGITS[c]

def str2float(s): s = s.split('.') s1 = s[0] //取整数部分 s2 = s[1:2] or ['0'] //取小数部分 s2 = s2[0] or '0' s2 = s2[::-1] //反转小数部分,以便从后往前加权求和 return (reduce(lambda x, y: x * 10 + y, map(char2num, s1))) + (reduce(lambda x, y: x / 10 + y, map(char2num, s2))) / 10

皓月灿阳

#2 Created at ... [Delete] [Delete and Lock User]

注释语法写串了


  • 1

Reply