python学习进阶一
2015-10-08 22:45
549 查看
map()函数
def format_name(s): return s.capitalize() print map(format_name, ['adam', 'LISA', 'barT']) Result: ['Adam', 'Lisa', 'Bart']
把函数作为参数
import math def add(x, y, f): return f(x) + f(y) print add(25, 9, math.sqrt) Result: 8.0
reduce()函数
def prod(x, y): return x*y print reduce(prod, [2, 4, 5, 7, 12]) Result: 3360
filter()函数
import math def is_sqr(x): return int(math.sqrt(x)) ** 2 == x print([x for x in filter(is_sqr, range(1, 100))]) Result: [1, 4, 9, 16, 25, 36, 49, 64, 81]
print sorted(['bob', 'about', 'Zoo', 'Credit'], key=lambda x:x.lower())
相关文章推荐
- 《机器学习实战》学习笔记:利用Adaboost元算法提高分类性能
- 【Python】Learn Python the hard way, ex17 文件复制
- 【Python】Learn Python the hard way, ex16 读写文件
- GemFI安装中的'Error: can't find library -lpthread required by python'
- python脚本执行Scapy出现IPv6警告WARNING解决办法
- LeetCode----Add and Search Word - Data structure design
- Python学习笔记 -- 第四章
- python 读中文乱码问题
- Python安装numpy,matplotlib,scikit_learn遇到的问题大汇总
- python&django 常见问题及解决方法
- Python中的单引号,双引号和三双引号
- 杨辉三角python实现
- python序列之:字符串(1)
- python 的取整问题
- Python Signal 信号 (二十一)
- Python 实例变量、类变量、静态变量 (十九)
- Python 装饰器 (十八)
- python之推导式介绍
- 通过python获得主机系统信息151008
- windows系统下,django1.8+python3.5使用pymysql链接 mysql数据库