zoukankan      html  css  js  c++  java
  • 【Python】python 2 map() reduce()

    利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']。

    1  def cg(name):
    2      return name[0].upper()+name[1:].lower()
    3  L = ['adam', 'LISA', 'barT']
    4  print map(cg,L1)

    编写一个prod()函数,可以接受一个list并利用reduce()求积。

    1  def prod(num1,num2):
    2      return num1*num2
    3  L = [3,7,5,9]
    4  print reduce(prod,L)
  • 相关阅读:
    Friends ZOJ
    2^x mod n = 1 HDU
    Paint the Grid Reloaded ZOJ
    Treap 模板
    bzoj进度条
    。。。
    bzoj
    。。。
    bzoj
    题解continue
  • 原文地址:https://www.cnblogs.com/yanglang/p/7118460.html
Copyright © 2011-2022 走看看