Discuss / Python / 人生苦短,我用Python

人生苦短,我用Python

Topic source

hcie_zpc

#1 Created at ... [Delete] [Delete and Lock User]
    s1,s2,s3 = s.partition('.')  # partition()直接分离出三元组
    Digits = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
    def fn(x,y):    # 数字转整数
        return x*10 + y
    def char2num(a):     # 字符转化数字
        return Digits[a]

    return reduce(fn,map(char2num,s1)) + reduce(fn,map(char2num,s3)) * pow(0.1,len(s3))

  • 1

Reply