Discuss / Python / 和1楼思路一样

和1楼思路一样

Topic source

philaradox

#1 Created at ... [Delete] [Delete and Lock User]
def charToInt(xxy):
    return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':0}[xxy]

def strToFloat(cha):
    if '.' in cha:
        newCha = cha.replace('.','')
        return reduce(lambda x,y : x*10 +y,map(charToInt,newCha)) / pow(10,(len(cha)-cha.find('.')-1))
    else:
        return reduce(lambda x,y : x*10 +y,map(charToInt,cha)) / 1.0

  • 1

Reply