Discuss / Python / exercise 1 and 2(map and reduce)

exercise 1 and 2(map and reduce)

Topic source

叫我_小军

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

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

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

second: from functools import reduce def prod(L): def mul(x1,x2): return x1*x2 return reduce(mul,L)

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

自己实在是太笨了,简单的题却花了很长的时间


  • 1

Reply