python的几种有用的函数 itertools库
2017-01-22 00:00
204 查看
import itertools b = [('a', -1), ('b', 'b1'), ('c', 'cs')] #笛卡尔积 list(itertools.product(*b)) [('a', 'b', 'c'), ('a', 'b', 'cs'), ('a', 'b1', 'c'), ('a', 'b1', 'cs'), (-1, 'b', 'c'), (-1, 'b', 'cs'), (-1, 'b1', 'c'), (-1, 'b1', 'cs')] #排列 list(itertools.permutations(b, 2)) [(('a', -1), ('b', 'b1')), (('a', -1), ('c', 'cs')), (('b', 'b1'), ('a', -1)), (('b', 'b1'), ('c', 'cs')), (('c', 'cs'), ('a', -1)), (('c', 'cs'), ('b', 'b1'))] #组合,没有重复 list(itertools.combinations(b, 2)) [(('a', -1), ('b', 'b1')), (('a', -1), ('c', 'cs')), (('b', 'b1'), ('c', 'cs'))] #组合,有重复 list(itertools.combinations_with_replacement(b, 2)) [(('a', -1), ('a', -1)), (('a', -1), ('b', 'b1')), (('a', -1), ('c', 'cs')), (('b', 'b1'), ('b', 'b1')), (('b', 'b1'), ('c', 'cs')), (('c', 'cs'), ('c', 'cs'))]
相关文章推荐
- 对新Python程序员有用的内建函数
- 感觉比较有用但实际没用到的python函数 map()&reduce()&lamdba()
- Python 有用的内建函数
- python几个有用的小函数
- 一个可能有用的封闭PGSQL操作的PYTHON函数
- learn python第五章:更多类 (第八节:有用的函数)
- python3 一些有用的函数
- python函数—定义参数的几种方式
- Oracle数据库中几种非常有用的函数(with……as等)
- python中函数参数传递的几种方法
- python 类的几种方法(函数)
- python里常用的几种函数类型
- python 一些有用的功能函数(持续更新)
- Python中有用的函数
- Python:几种函数的用法
- python 零散记录(五) import的几种方式 序列解包 条件和循环 强调getattr内建函数
- Python中有用的内建函数
- 对python字符串操作的几种方法(函数)
- python 函数的参数的几种类型
- 简单了解Python中的几种函数