Python 模块 itertools
2015-03-16 21:01
183 查看
python 2.6 引入了itertools模块,使得排列组合的实现非常简单:
有序排列:e.g., 4个数内选2个排列:
无序组合:e.g.,4个数内选2个:
import itertools
有序排列:e.g., 4个数内选2个排列:
>>> print list(itertools.permutations([1,2,3,4],2)) [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]
无序组合:e.g.,4个数内选2个:
>>> print list(itertools.combinations([1,2,3,4],2)) [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
count 原型: count(start[, step]) 返回: start, start+step, start+2*step, ... (以start为首项, step为公差的等差数列) example: count(10):10, 11, 12, 13, .....
相关文章推荐
- python模块-itertools
- python 高效的 itertools 模块
- python的数学函数(1)-python组合函数模块itertools
- Python学习之内建模块(3):itertools
- python模块之hashlib: md5和sha算法
- python模块之quopri: quoted-printable编解码
- python模块之zipfile
- Python模块的交叉引用问题
- Python指南--模块
- Python的内存泄漏及gc模块的使用
- python模块之poplib: 用pop3收取邮件
- python模块之email: 电子邮件编码解码 (一、解码邮件)
- python模块之HTMLParser: 解析html,获取url
- python模块之StringIO
- python模块之uuid
- python模块之sqlite数据库
- C++ Boost 之Python(生成一个扩展模块)
- Python模块的交叉引用问题
- 简明Python 教程 --模块
- python模块之email: 电子邮件编码解码 (二、编码邮件)