Discuss / Python / 交作业

交作业

Topic source

第一题

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

第二题

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}
    index = s.find('.')
    def char2num(s):
        return DIGITS[s]
    to_int = reduce(lambda x, y: x * 10 + y, map(char2num, s.replace('.','')))
    return to_int * (10 ** (index - len(s) + 1))                # s含小数点,所以index-len(s)会多减去一位数,需要加1补足

去鸭冲鸭

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

这个答案最通俗易懂

赞一个,很不错


  • 1

Reply