Discuss / Python / 看了一整天Python,来打个卡

看了一整天Python,来打个卡

Topic source

林金壕

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

第一题:

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

L1 = ['adam', 'LISA', 'barT']
L2 = list(map(normailze, L1))
print(L2)

第二题:

from functools import reduce

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

print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))

第三题:

from functools import reduce

def str2float(s):
    return reduce(lambda x, y: x * 10 + y, [int(c) for c in s if c != '.']) / pow(10, len(s) - s.index('.') - 1)
print('str2float(\'123.456789\') =', str2float('123.456789'))

  • 1

Reply