def str2float(s): DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} n = 0 while(s[n] != '.'): n = n + 1
def char2num(s): return DIGITS[s] def fn(x, y): return x*10+y return reduce(fn, map(char2num, s[:n]))+reduce(fn, map(char2num, s[n+1:]))/10**(len(s)-n-1)
兄弟 你真是个天才 吾等初学者的楷模
Sign in to make a reply
顾西瓜哇咔咔
def str2float(s): DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} n = 0 while(s[n] != '.'): n = n + 1