Discuss / Python / 作业

作业

Topic source

柴哲远

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

def normalize(name):

    return name.title()

def prod(L):

    def multi(x,y):

        return x*y

    return reduce(multi,L)

def str2float(s):

    a=s.index('.')

    b=s.replace('.','')

    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

    def f(x,y):

        return 10*x+y

    def char2float(b):

        return DIGITS[b]

    return reduce(f,map(char2float,b))/(10**a)


  • 1

Reply