#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进行排列组合的更多相关文章

  1. Python小技巧:使用*解包和itertools.product()求笛卡尔积

    [问题] 目前有一字符串s = "['a', 'b'],['c', 'd']",想把它分开成为两个列表: list1 = ['a', 'b'] list2 = ['c', 'd'] ...

  2. Python小技巧:使用*解包和itertools.product()求笛卡尔积(转)

    leetcode上做提示时候看到有高人用这个方法解题 [问题] 目前有一字符串s = "['a', 'b'],['c', 'd']",想把它分开成为两个列表: list1 = [' ...

  3. Python中的itertools.product

    例子1:import itertoolsa = itertools.product([1,2,3],[100,200])print(a)for item in itertools.product([1 ...

  4. 机器学习入门-混淆矩阵-准确度-召回率-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], [ ...

  5. Python中unittest采用不同的参数组合产生独立的test case

    我们在使用Python的unittest做自动化或者单元测试时,有时需要一个测试用例根据不同的输入.输出组合而执行多次,但是,unittest中一个用例只能有一组参数组合执行,如果采用循环的方式,在生 ...

  6. python面向对象之静态属性/静态方法/类方法/组合

    继续学习,不要松懈 #!/usr/bin/env python # coding:utf-8 class Campus: def __init__(self,name,addr,type): self ...

  7. Python基础系列讲解——继承派生和组合的概念剖析

    Python作为一门面向对象的语言,它的面向对象体系中主要存在这么两种关系,一个是“类”和“实例”的关系,另一个是“父类”和“子类”的关系. 所谓“类”是从一堆对象中以抽象的方式把相同的特征归类得到的 ...

  8. Python开发基础-Day18继承派生、组合、接口和抽象类

    类的继承与派生 经典类和新式类 在python3中,所有类默认继承object,但凡是继承了object类的子类,以及该子类的子类,都称为新式类(在python3中所有的类都是新式类) 没有继承obj ...

  9. Python 面向对象--继承,实现,依赖,关联,聚合,组合

    一. 继承 继承指的是子类继承父类除私有内容以外的其他所有内容, 并且子类具有增加自己新内容的能力. 举例说明: class Animal: print("吃是动物的本能") cl ...

随机推荐

  1. f-stack中nginx配置后make出现error: ignoring return value of ‘ftruncate’

    问题 Nginx 配置后 make 出现error: src/os/unix/ngx_process_cycle.c: In function 'ngx_start_worker_processes' ...

  2. vue.js数组追加合并与对象追加合并的

    今天在做懒加载的时候遇到的问题,在网上搜索找到的答案不是很清晰,就来写一下,方便以后使用. 直接上图吧 官方连接:https://cn.vuejs.org/v2/guide/reactivity.ht ...

  3. LeetCode29.两数相除 JavaScript

    给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使用乘法.除法和 mod 运算符. 返回被除数 dividend 除以除数 divisor 得到的商. 示例 1: 输 ...

  4. Nested Loops,Hash Join 和 Sort Merge Join. 三种不同连接的不同:

    原文:https://blog.csdn.net/tianlesoftware/article/details/5826546 Nested Loops,Hash Join 和 Sort Merge ...

  5. javascript 使用 匿名 箭头函数 this的变化

    处理html 页面 <body> <div class="main"> <div class="up"> <div c ...

  6. VS Code 的常用快捷键及插件(前端)

    一.vs code 的常用快捷键 1.注释: a) 单行注释:[ctrl+k,ctrl+c] 或 ctrl+/ b) 取消单行注释:[ctrl+k,ctrl+u] (按下ctrl不放,再按k + u) ...

  7. iframe 框架 父页面与子界面之间的变量、函数、元素获取

    1.获取页面上的iframe 1-1. document.getElementById('iframeId'): 1-2. window.frames[0].window.frames['frameN ...

  8. java学习无止境,工资价更高

    原 推荐10个Java方向最热门的开源项目(8月) 2018年08月28日 17:54:32 SnailClimb在CSDN 阅读数:849   版权声明:本文为博主原创文章,未经博主允许不得转载. ...

  9. 记一次学习PHP中的错误

    今天学习PHP时,回想起一段代码 <?php> $i = true; $o = true; $p = false; if($i or $o and $p){ echo '输出为'.'tru ...

  10. pow函数(数学次方)在c语言的用法,两种编写方法实例( 计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值)

    关于c语言里面pow函数,下面借鉴了某位博主的一篇文章: 头文件:#include <math.h> pow() 函数用来求 x 的 y 次幂(次方),x.y及函数值都是double型 , ...