Discuss / Python / 第三题来一个超长的代码,哈哈

第三题来一个超长的代码,哈哈

Topic source
#第一题
L = ['adam', 'LISA', 'barT']
def normalize(name):
    return name.title()
L2 = list(map(normalize,L))
print(L2)

#第二题
def prod(L):
    return reduce(lambda x, y : x * y, L)

#第三题
def char2num(char):
    return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[char]
def str2float(str):
    L = str.split(sep = '.')
    return reduce(lambda x, y : x * 10 + y, map(char2num,L[0])) + reduce(lambda x, y : x / 10 + y , list(map(char2num,L[1]))[::-1]) / 10

['Adam', 'Lisa', 'Bart']

prod([3,5,7,9]) 945 str2float('123.456789') 123.456789

gylpnj

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

第三题跟你写的一模一样...23333


  • 1

Reply