Discuss / Python / 慢慢写,第三题不会

慢慢写,第三题不会

Topic source
第一题:
  1 #!/usr/bin/env python3
  2 def normalize(name):
  3     return name.title()
  4 L1 = ['adam', 'LISA', 'barT']
  5 L2 = list(map(normalize, L1))
  6 print (L2)
~                
第二题:
  1 #!/usr/bin/env python3
  2 from functools import reduce
  3 def prod(L):
  4     return reduce(lambda x, y: x * y , L)
  5 
  6 print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
第二题for循环:
  1 #!/usr/bin/env python3
  2 from functools import reduce
  3 def prod(L):
  4     s = 1
  5     for i in L:
  6         s = i * s
  7     return s
  8 L = [3,5,7,9]
  9 print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))

-- coding:utf-8 --

from functools import reduce def prod(L): def a(x,y): return x*y return reduce(a,L) print(prod([3,5,7,9]))


  • 1

Reply