def str2float(s): n = s.replace('.','') DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} def abc(s): return DIGITS[s] return reduce(lambda x,y:x*10+y,map(abc,n))/1000
然而你这个还是错的,小数点后面不是三位数的时候,就是错的了
Sign in to make a reply
z_潇旭
def str2float(s): n = s.replace('.','') DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} def abc(s): return DIGITS[s] return reduce(lambda x,y:x*10+y,map(abc,n))/1000