Discuss / Python / 感觉你们写的好复杂

感觉你们写的好复杂

Topic source

jstdit112

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

第一题:

def normalize(name):

    name = name.lower()

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

第二题:

def prod(L):

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

第三题:

    s1 = s.split('.')[0]

    s2 = s.split('.')[1]

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

    r1 = reduce(lambda x, y: x * 10 + y, map(lambda x: DIGITS[x], s1))

    r2 = reduce(lambda x, y: x * 0.1 + y, map(lambda x: DIGITS[x], s2[::-1]))

    return r1 + r2 * 0.1


  • 1

Reply