Discuss / Python / 第三题

第三题

Topic source

林水游

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

` def str2float(s): def char2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] def fn(s): L = s.split('.') s1 = reduce(lambda x,y:x10+y,map(char2num,L[0])) s2 = reduce(lambda x,y:x10+y,map(char2num,L[1])) s2 = s2/10**len(L[1]) return s1+s2 return fn(s)


  • 1

Reply