Discuss / Python / code example

code example

Topic source
#!/usr/bin/python3.5
#-*- coding:utf-8 -*-
from functools import reduce
def str2int(s):
    def getint(x):
        return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[x]
    return reduce(lambda x,y:x*10+y,map(getint,s))
def str2float(s):
    strl=s.split('.')
    if len(strl)>=2:
        return str2int(reduce(lambda x,y:x+y,strl))/(10**len(strl[-1]))
    return str2int(s1)

the last return statement in str2float function has a error.'s1' should be 'strl'


  • 1

Reply