【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 ...
随机推荐
- SQL SERVER或oracl如何判断删除列
ORACLE: BEGIN EXECUTE IMMEDIATE 'DROP TABLE CUX_PO_VENDORS';EXCEPTION WHEN OTHERS THEN NULL;END ...
- Facade(外观)模式
1. 概述 外观模式,我们通过外观的包装,使应用程序只能看到外观对象,而不会看到具体的细节对象,这样无疑会降低应用程序的复杂度,并且提高了程序的可维护性.例子1:一个电源总开关可以控制四盏灯.一个风扇 ...
- spring cloud config将配置存储在数据库中
Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库,放在本地是将将所有的配置文件统一写在Config Server工程目录下,如果需要修改配置,需要重启c ...
- Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.UserService' that could not be found
Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.Us ...
- 帝国CMS站点迁移
1.重新安装xmapp环境 安装包地址 链接:https://pan.baidu.com/s/1OSwlP90G9VMAZYVXMG245Q 提取码:gnfr 2.安装后启动 3.复制数据库信息 将旧 ...
- 构建WebGL目标时的内存考量
Memory Considerations when targeting WebGL 构建WebGL目标时的内存考量 Memory in Unity WebGL can be a constraini ...
- 物联网通信 - RESTDemo示例程序(C#版本)
技术:wcf+http post+json(.net4.0 + jdk1.8) 运行环境:vs2010+java 概述Server开放RESTful API接口,供应用程序/移动App/嵌入式qt通过 ...
- STM32使用FatFs
1.定义一些变量在我们代码开始的部分,先定义一些变量供我们使用.这里选择几个来解析一下.第一个FIL file;这个变量是文件的结构体变量,记录了我们打开的文件的信息.使用f_open等函数的时候都要 ...
- Python学习——编程语言介绍
开发语言 高级语言:基于C/汇编等封装的语言,如Python.Java.C#.PHP.Go.ruby.C++……生成字节码让C/汇编去识别 低级语言:直接让计算机底层能识别成机器码的语言(计算机再将机 ...
- Go黑帽子
使用go语言来实现python黑帽子和绝技的代码 1.unix密码破解器 package main import( "bufio" "flag" "i ...