python 实现排列组合
2024-09-02 22:48:28
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
可以根据你需要随意组合
最新文章
- GitHub实战系列~4.把github里面的库克隆到指定目录+日常使用 2015-12-11
- SQL JOIN\SQL INNER JOIN 关键字\SQL LEFT JOIN 关键字\SQL RIGHT JOIN 关键字\SQL FULL JOIN 关键字
- MAC中Django中runserver提示Can't connect to local MySQL server through socket '/tmp/mysql.sock错误
- 【linux命令】grep
- jquery学习记录
- libevent使用
- MySQL基础学习之索引
- Oracle 行拼接 wmsys.wm_concat扩展
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
- 第三代搜索推出网民评价系统,seo末日还会远吗?
- Windows Phone – 裁剪图片 (Crop Image)
- 捕鱼达人代码例子下载地址 mac版
- ZJOI2017 day1滚粗记
- Mac和Windows系统下Mysql数据库的导入导出
- django捡破烂
- ubuntu sudoers配置错误
- 【python接口自动化-requests库】【三】优化重构requests方法
- what's the 场外交易
- SpringMVC(前端设计模式)简介
- 【MFC】OnInitDialog