Discuss / Python / 作业

作业

Topic source

GARRY2019

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

from functools import reduce

def normalize(name):

    return name[0].upper()+name[1:]

def prod(L):

    return reduce(lambda x, y: x*y,L)

def str2float(s):

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

    def char2num(s):

        return DIGITS[s]

    ss=s.split('.')

    first=reduce(lambda x,y:x*10+y,map(char2num,ss[0]))

    second = reduce(lambda x, y: x *10+ y, map(char2num, ss[1]))

    return first+(second/10**len(ss[1]))


  • 1

Reply