Discuss / Python / 交作业

交作业

Topic source

倒吃甘蔗

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

第一题

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

第二题

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

第三题

    def f1(x, y):
        return x * 10 + y
    def char2num(s):
        digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
        return digits[s]
    return reduce(f1, map(char2num, s[0:3])) + reduce(f1, map(char2num, s[4:]))*10**-3

  • 1

Reply