Python排列组合实验
2015-06-12 12:13
736 查看
import itertools 排列: 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)] 组合:4个数内选2个: >>> print list(itertools.combinations([1,2,3,4],2)) [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] _____________________________________ ABCDE 5个数的排列(去掉重复): >>>len(set(list(itertools.permutations(['A','B','C','D','E'],5)))) 120 AABCD 5个数不同的排列(去掉重复): >>>len(set(list(itertools.permutations(['A','A','B','C','D'],5)))) 60 AABBC(去掉重复): >>> len(set(list(itertools.permutations(['A','A','B','B','C'],5)))) 30 AAABC(去掉重复): >>> len(set(list(itertools.permutations(['A','A','A','B','C'],5)))) 20 AAABB(去掉重复): >>> len(set(list(itertools.permutations(['A','A','A','B','B'],5)))) 10 AAAAB(去掉重复): >>> len(set(list(itertools.permutations(['A','A','A','A','B'],5)))) 5
相关文章推荐
- Java调用Python(续)
- Python环境变量的引入
- python yield用法举例说明
- Python 知识点
- 使用Pyjnius 从python调用自定义Java方法
- python django web项目的构建步骤(二)
- python通过POST提交页面请求
- python学习笔记(二)
- IDF 逆向题 python ByteCode
- 变量和字符串
- python log学习笔记
- 生产者、消费者问题,python实现
- Python 学习笔记5
- 用python设计的一个小游戏
- Python2中的raw_input() 与 input()
- Windows下实现Python2和Python3两个版共存的方法
- Python3中的2to3转换工具使用示例
- Python中unittest模块做UT(单元测试)使用实例
- Python学习笔记 -- 序列(四)元组
- 初步了解python