Discuss / Python / 作业

作业

Topic source

dijkstrafloyd

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

第一题

l5 = ['adam', 'LISA', 'barT'];
print(list(map(lambda s: reduce(lambda x, y: x + y, [s[0].upper()] + [c.lower() for c in s[1:]]), l5)))

第二题

def prod(l):
    return reduce(lambda x, y: x * y, l)
print(prod([3, 5, 7, 9]))

第三题

s1 = '123.456'
print(reduce(lambda x, y: 10 * x + y, map(int, s1.split('.')[0])) + 0.1 * reduce(lambda x, y: 0.1 * x + y, map(int, reversed(s1.split('.')[1]))))

  • 1

Reply