Discuss / Python / 打卡

打卡

Topic source

练习1:

def normalize(name):

    name = name[0].upper() + name[1:].lower()

    return name     

练习2:

def prod(L):

    def mul(x, y):

        return x * y

    return reduce(mul, L)

练习3:

    i = s.index('.')

    s1 = s[:i]

    s2 = s[i+1:]

    def dig(x):

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

        return digits[x]

    def fn(x, y):

        return x * 10 + y

    return reduce(fn, map(dig, s1)) + pow(10, -i) * reduce(fn, map(dig, s2))


  • 1

Reply