def str2float(s):
arr = s.split('.')
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
integer = reduce(lambda x,y:x*10+y,map(lambda x:DIGITS[x],arr[0]))
decimal = reduce(lambda x,y:x*0.1+y,map(lambda x:DIGITS[x],arr[1][::-1]))*0.1
return integer + decimal
Sign in to make a reply
DerSpiegel镜
def str2float(s):
arr = s.split('.')
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
integer = reduce(lambda x,y:x*10+y,map(lambda x:DIGITS[x],arr[0]))
decimal = reduce(lambda x,y:x*0.1+y,map(lambda x:DIGITS[x],arr[1][::-1]))*0.1
return integer + decimal