Discuss / Python / 第三题

第三题

Topic source

DerSpiegel镜

#1 Created at ... [Delete] [Delete and Lock User]

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


  • 1

Reply