Discuss / Python / 这节题目比较有启发性

这节题目比较有启发性

Topic source

________却

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

-- coding: utf-8 --

第一题

def normalize(name): return name.capitalize()

测试:

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

-- coding: utf-8 --

第二题

from functools import reduce def prod(L): return reduce(lambda x,y: xy, L) print('3 5 7 9 =', prod([3, 5, 7, 9]))

-- coding: utf-8 --

第三题

from functools import reduce def str2float(s): a = s.split('.') return reduce(lambda x,y: x+y/(10*(a[1].len())), map(lambda m: reduce(lambda x,y:10x+y, map(int, m)),a)) print('str2float(\'123.456\') =', str2float('123.456'))


  • 1

Reply