Discuss / Python / 作业 - 第三题

作业 - 第三题

Topic source

greatzues

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

from functools import reduce

def str2float(s): w = s.split('.') w[1] = '0' + w[1] L = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9} n1 = reduce(lambda x ,y : x 10 + y , map(lambda x : L[x],w[0])) n2 = reduce(lambda x ,y : x 0.1 + y, map(lambda x : L[x],w[1][::-1])) return n1 + n2

想了一晚上,终于写出来了!


  • 1

Reply