Discuss / Python / 第三题

第三题

Topic source

if '.' not in s: temp = {str(i):i for i in range(10)}

#     t = s.index('.')
    return reduce(lambda x,y:x*10+y ,map(lambda x:temp[x],s))   
else:
    a = s[:s.index('.')]
    b = s[s.index('.')+1:]
    temp = {str(i):i for i in range(10)}
    return((reduce(lambda x,y:x*10+y ,map(lambda x:temp[x],a)))+(reduce(lambda x,y:x*10+y ,map(lambda x:temp[x],b)))/(pow(10,len(b))))

  • 1

Reply