【python 3.6】使用itertools.product进行排列组合
#python 3.6
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'BH8ANK' import itertools color = [
'red',
'green',
'blue',
'white'
] target = [
'bike',
'pencil',
'desk',
'gun',
'car'
] type = [
'big',
'small'
] data_source = itertools.product(color,target,type)
data_source_list = [it for it in data_source]
print(data_source_list)
输出如下:
[('red', 'bike', 'big'), ('red', 'bike', 'small'), ('red', 'pencil', 'big'), ('red', 'pencil', 'small'), ('red', 'desk', 'big'), ('red', 'desk', 'small'), ('red', 'gun', 'big'), ('red', 'gun', 'small'), ('red', 'car', 'big'), ('red', 'car', 'small'), ('green', 'bike', 'big'), ('green', 'bike', 'small'), ('green', 'pencil', 'big'), ('green', 'pencil', 'small'), ('green', 'desk', 'big'), ('green', 'desk', 'small'), ('green', 'gun', 'big'), ('green', 'gun', 'small'), ('green', 'car', 'big'), ('green', 'car', 'small'), ('blue', 'bike', 'big'), ('blue', 'bike', 'small'), ('blue', 'pencil', 'big'), ('blue', 'pencil', 'small'), ('blue', 'desk', 'big'), ('blue', 'desk', 'small'), ('blue', 'gun', 'big'), ('blue', 'gun', 'small'), ('blue', 'car', 'big'), ('blue', 'car', 'small'), ('white', 'bike', 'big'), ('white', 'bike', 'small'), ('white', 'pencil', 'big'), ('white', 'pencil', 'small'), ('white', 'desk', 'big'), ('white', 'desk', 'small'), ('white', 'gun', 'big'), ('white', 'gun', 'small'), ('white', 'car', 'big'), ('white', 'car', 'small')]
即,itertools.product(list1,list2......listn),将list1到listn中的元素依次排列组合,返回一个新的list
【python 3.6】使用itertools.product进行排列组合的更多相关文章
- Python小技巧:使用*解包和itertools.product()求笛卡尔积
[问题] 目前有一字符串s = "['a', 'b'],['c', 'd']",想把它分开成为两个列表: list1 = ['a', 'b'] list2 = ['c', 'd'] ...
- Python小技巧:使用*解包和itertools.product()求笛卡尔积(转)
leetcode上做提示时候看到有高人用这个方法解题 [问题] 目前有一字符串s = "['a', 'b'],['c', 'd']",想把它分开成为两个列表: list1 = [' ...
- Python中的itertools.product
例子1:import itertoolsa = itertools.product([1,2,3],[100,200])print(a)for item in itertools.product([1 ...
- 机器学习入门-混淆矩阵-准确度-召回率-F1score 1.itertools.product 2. confusion_matrix(test_y, pred_y)
1. itertools.product 进行数据的多种组合 intertools.product(range(0, 1), range(0, 1)) 组合的情况[0, 0], [0, 1], [ ...
- Python中unittest采用不同的参数组合产生独立的test case
我们在使用Python的unittest做自动化或者单元测试时,有时需要一个测试用例根据不同的输入.输出组合而执行多次,但是,unittest中一个用例只能有一组参数组合执行,如果采用循环的方式,在生 ...
- python面向对象之静态属性/静态方法/类方法/组合
继续学习,不要松懈 #!/usr/bin/env python # coding:utf-8 class Campus: def __init__(self,name,addr,type): self ...
- Python基础系列讲解——继承派生和组合的概念剖析
Python作为一门面向对象的语言,它的面向对象体系中主要存在这么两种关系,一个是“类”和“实例”的关系,另一个是“父类”和“子类”的关系. 所谓“类”是从一堆对象中以抽象的方式把相同的特征归类得到的 ...
- Python开发基础-Day18继承派生、组合、接口和抽象类
类的继承与派生 经典类和新式类 在python3中,所有类默认继承object,但凡是继承了object类的子类,以及该子类的子类,都称为新式类(在python3中所有的类都是新式类) 没有继承obj ...
- Python 面向对象--继承,实现,依赖,关联,聚合,组合
一. 继承 继承指的是子类继承父类除私有内容以外的其他所有内容, 并且子类具有增加自己新内容的能力. 举例说明: class Animal: print("吃是动物的本能") cl ...
随机推荐
- wordpress安装(ubuntu+nginx+php+mariadb)
一. 环境 ubuntu12.04.4 nginx 1.6.0 mariadb 10.0 更新系统补丁 sudo apt-get update sudo apt-get dist-upgrade ...
- 获取并安装XWAF框架压缩包(2)
建议在Eclipse环境下使用XWAF框架来开发用户的Web项目,并遵循以下步骤和约定. 1.获取XWAF框架压缩包文件 程序员点击下列地址免费下载XWAF框架的压缩包文件:XWAF框架压缩文件 2. ...
- case when then else end 与 decode 的区别
case when then else end : 条件可以有 等于 ,大于 ,小于 与 decode : 条件只可以有等于的.
- MessageBox.Show用法
private void button3_Click(object sender, EventArgs e) { MessageBox.Show(" 1 个参数 "); } ~ ...
- iOS 推送功能打包后获取不到deviceToken
公司项目用ionic3构建, 用了极光推送插件(cordova-plugin-jpush). 开发时一切将各种Bundle Id, 推送证书等都绑定完测试一切正常. 可是要给测试人员打Ad-Hoc包时 ...
- 一次tomcat的调优记录
项目本身需要上传模型,使用的是springboot1.5.3. 上传的模型比较大,下载的过程中就出现了问题(下载是su调用的java接口,其开发并非本人负责,不可更改) 问题在于,下载的时候tomca ...
- linux 学习第十六天(Samba配置)
Samba 服务 yum install samba mv smb.conf smb.conf.bak cat smb.conf.bak | grep -v "#" | grep ...
- Delphi 的TStringBuilder防止服务器内存碎片化
Delphi 2009+ 的 System.SysUtils提供了一个类似.Net的StringBuilder,用于存储字符数组. 很多人不明白为什么要用TStringBuilder, Delphi中 ...
- 嵌入式C语言自我修养 07:地址对齐那些事儿
7.1 属性声明:aligned GNU C 通过 __atttribute__ 来声明 aligned 和 packed 属性,指定一个变量或类型的对齐方式.这两个属性用来告诉编译器:在给变量分配存 ...
- python 时间time模块介绍和应用
1.其中format_string 类型的时间和struct_time之间可以转换,timestamp时间戳可以和struct_time之间进行转化,但是时间戳和格式化时间是不能直接转换的. time ...