Discuss / Python / 不知道次方是 10** 这么用的。。也不知到可以用 .find() 和 .split()

不知道次方是 10** 这么用的。。也不知到可以用 .find() 和 .split()

Topic source
from functools import reduce

def str2float(s):
    def turn(a):
        return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':'.'}[a]
    def time(max):
        k=1
        a=1
        while k<=max:
            k=k+1
            a=a*10
        return a
    n=0
    while n<len(list(map(turn,s))):
        n=n+1
        if list(map(turn,s))[n-1]=='.':
            break
    L=list(map(turn,s))
    L.pop(n-1)
    n=len(L)-n+1
    return reduce(lambda x,y:10*x+y,L)/time(n)

  • 1

Reply