python 实现排列组合
1.python语言简单、方便,其内部可以快速实现排列组合算法,下面做简单介绍、
2.一个列表数据任意组合
2.1主要是利用自带的库
#_*_ coding:utf-8 _*_
#__author__='dragon'
import itertools
list1 = [1,2,3,4,5]
list2 = []
for i in range(1,len(list1)+1):
iter = itertools.combinations(list1,i)
list2.append(list(iter))
print(list2)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
3.排列的实现
#_*_ coding:utf-8 _*_
#__author__='dragon'
import itertools
list1 = [1,2,3,4,5]
list2 = []
for i in range(1,len(list1)+1):
iter = itertools.permutations(list1,i)
list2.append(list(iter))
print(list2)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
可以根据你需要随意组合
python 实现排列组合的更多相关文章
- python编写排列组合,密码生产功能
python编写排列组合 python在编写排列组合是会用到 itertools 模块 排列 import itertools mylist = list(itertools.permutation ...
- 【Python】排列组合itertools & 集合set
■itertools 利用python的itertools可以轻松地进行排列组合运算 itertools的方法基本上都返回迭代器 比如 •itertools.combinations('abcd',2 ...
- python 编写排列组合
python在编写排列组合是会用到 itertools 模块 排列 import itertools mylist = list(itertools.permutations([)) # 全排列 p ...
- Python实现排列组合
# -*- coding: utf-8 -*-"""Created on Sat Jun 30 11:49:56 2018 @author: zhen"&quo ...
- python算法-排列组合
排列组合 一.递归 1.自己调用自己 2.找到一个退出的条件 二.全排列:针对给定的一组数据,给出包含所有数据的排列的组合 1:1 1,2:[[1,2],[2,1]] 1,2,3:[[1,2,3],[ ...
- python之排列组合测试
# test permutations and combinations import itertools as it for i in it.combinations('abcd',2): prin ...
- python解决排列组合
笛卡尔积:itertools.product(*iterables[, repeat]) import itertools for i in itertools.product('BCDEF', re ...
- python自带的排列组合函数
需求: 在你的面前有一个n阶的台阶,你一步只能上1级或者2级,请计算出你可以采用多少种不同的方法爬完这个楼梯?输入一个正整数表示这个台阶的级数,输出一个正整数表示有多少种方法爬完这个楼梯. 分析:提炼 ...
- 排列组合python
python 的 itertools模块 可以专业的处理的排列组合问题 写在自己博客里,怕下次找不到喽
随机推荐
- LInux下LD_LIBRARY_PATH的作用与设置
LD_LIBRARY_PATH环境变量主要是用于指定动态链接器(Id)超早elf可执行文件运行时所依赖的动态库(so)的路径,其内容是以冒号分隔的路径列表. Id链接器优先在该变量设置的路径中查找,若 ...
- 获取request错误信息
from: https://stackoverflow.com/questions/19370436/get-errno-from-python-requests-connectionerror 当使 ...
- 迷你MVVM框架 avalonjs 学习教程22、avalon性能大揭密
avalon之所以能在页面处理1W个绑定(angular对应的数字是2000),出于两个重要设计--基于事件驱动的双向绑定链及智能CG回收机制. avalon的双向绑定链是通过Object.defin ...
- servlet和JSP页面乱码问题
JSP和Servlet的中文乱码处理 前几天学习了JSP和Servlet中有关中文乱码的一些问题,写成了博客,今天进行更新一下.应该是可以解决日常的乱码问题了.现在作以下总结希望对需要的人有所帮助.我 ...
- Windows 2008开启远程桌面连接
具体请看下面的截图. 最重要的就是要打开远程允许远程桌面的默认端口 3389 的入站规则,我第一次弄,这一端口没打开,折腾了很久!!! 第一.首先打开“服务器管理器”—“配置”—“高级安全Window ...
- ID3、C4.5和cart算法比较(转)
转自:https://www.zhihu.com/question/27205203
- chrome 调试参数(鼠标事件)
1.监听鼠标事件: monitorEvents(document.body, 'mouse') 取消监听: unmonitorEvents(document.body) 原文链接: https://b ...
- Python+Webdriver,中文前加u是unicode格式编码的意思
Python+Webdriver写脚本时,对一些输入框赋值会涉及到输入中文,这时需要在中文前加u 举个例子,在用百度搜索时,要在搜索输入框内输入值, 我用的编码格式是utf-8,向输入框内输入值是:d ...
- Spring简单获得实体类的实例, 使用ApplicationContext()方法的几点注意事项
今天接触了Spring的初步用法, 感觉跟实例化实体类没啥区别, 像这种简单的代码还不如直接实例化来的方便, 这样使用Spring的话总共需要三个文件 第一个当然是一个实体类了, 定义好属性, get ...
- Windows XP with SP3大客户免激活日文版
原贴地址:http://www.humin.com.cn/ja_windows_xp_professional_with_service_pack_3_x86_dvd_vl_x14-74058-iso ...