Discuss / Python / My answer

My answer

Topic source

winner丶John

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

No.1

def normalize(name):

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

No.2

def prod(L):

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

No.3

def str2float(s):

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

    s1, s2 = s[:s.index('.')], s[s.index('.') + 1:] 

    L1, L2 = map(lambda x: DIGITS[x], s1), map(lambda x: DIGITS[x] / 10 ** len(s2), s2)

    return sum(map(lambda z: reduce(lambda x, y: 10 * x + y, z), [L1, L2]))


  • 1

Reply