Discuss / Python / 写了个非常丑陋的代码

写了个非常丑陋的代码

Topic source

尼柔斯_

#1 Created at ... [Delete] [Delete and Lock User]
import functoolsdef str2float(s):    s1=str(s).split('.')[0]    s2 = str(s).split('.')[1]    def dict (s):        dict={'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}        return dict[s]    def tofloat(x,y):        return x*10+y    return functools.reduce(tofloat,list(map(dict,s1)))+(functools.reduce(tofloat,list(map(dict,s2))))/(10**len(s2))print('str2float(\'123.456\') =', str2float('123.456'))

  • 1

Reply