1 product

1.1 一个generator函数

因此它的返回值是一个iterator,可以用for遍历。

1.2 计算product的参数分类

1.2.1 dict和list

只用了dict的key,没有用dict的value。

例子:

>>> d1={'x1':1, 'y1':2, 'z1':3}
>>> d2={'x2':2, 'y2':3}
>>> dd={'t1':d1,'t2':d2}
>>> l1=[a,b,c,d]

>>> a=product(dd,l1)
>>> for i in a:
...     print i
...
('t2', 'a')
('t2', 'b')
('t2', 'c')
('t2', 'd')
('t1', 'a')
('t1', 'b')
('t1', 'c')
('t1', 'd')

1.2.2 dict和dict

同样丢掉了value。

例子:

b= product(d1,d2)
>>> for i in b:
...     print i
...
('y1', 'x2')
('y1', 'y2')
('x1', 'x2')
('x1', 'y2')
('z1', 'x2')
('z1', 'y2')

python itertools的更多相关文章

  1. 转:Python itertools模块

    itertools Python的内建模块itertools提供了非常有用的用于操作迭代对象的函数. 首先,我们看看itertools提供的几个"无限"迭代器: >>& ...

  2. python, itertools模块

    通过itertools模块,可以用各种方式对数据进行循环操作 1, chain() from intertools import chain for i in chain([1,2,3], ('a', ...

  3. python itertools 模块

    Python的内建模块itertools提供了非常有用的用于操作迭代对象的函数 首先,我们看看itertools提供的几个“无限”迭代器: >>> import itertools ...

  4. 《笔记》Python itertools的groupby分组数据处理

    今天遇到这么一个需求,需要将这样的数据进行分组处理: [(, ), (, ), (, ), (, ), (, ), (, )] 处理之后我可能需要得到这样的结果: [(, (, , (, , (, ) ...

  5. Python itertools模块详解

    这货很强大, 必须掌握 文档 链接 http://docs.python.org/2/library/itertools.html pymotw 链接 http://pymotw.com/2/iter ...

  6. python itertools 模块讲解

    1.介绍itertools 是python的迭代器模块,itertools提供的工具相当高效且节省内存. 使用这些工具,你将能够创建自己定制的迭代器用于高效率的循环. - 无限迭代器 itertool ...

  7. Python itertools/内置函数

    https://docs.python.org/3.5/library/itertools.html#itertools.starmap // https://docs.python.org/3.5/ ...

  8. Python itertools.combinations 和 itertools.permutations 等价代码实现

    最近编程时经常要用到排序组合的代码,想当年还抱着一些情况买了一本<组合数学>,不过现在这货也不知道被自己放哪里了,估计不会是垫桌子腿了吧. 由于去年去东北大学考博面试的时候遇到过可能涉及排 ...

  9. python itertools模块练习

    参考 <python标准库> 也可以参考Vamei博客 列表用着很舒服,但迭代器不需要将所有数据同时存储在内存中. 本章练习一下python 标准库中itertools模块 合并 和 分解 ...

  10. [python] itertools库学习

    最近做 cyber-dojo上的题,好几道都要用到排列组合.一开始我还老老实实自己写算法.后来一想,不对呀!python有那么多的库,为啥不用呢? 于是搜了下,发现这个:itertools 使用 he ...

随机推荐

  1. 条款21:必须返回对象时,别妄想返回其reference(Don't try to return a reference when you must return an object)

    NOTE: 1.绝不要返回pointer或reference 指向一个local stack 对象,或返回reference 指向一个heap-allocated对象,或返回pointer 或refe ...

  2. Mybatis中实体类属性和数据列之间映射的四种办法

    http://blog.csdn.net/lmy86263/article/details/53150091 Mybatis不像hibernate中那么自动化,通过@Column注解或者直接使用实体类 ...

  3. NowCoder栗酱的连通图(最小生成树, 结论)

    链接: https://www.nowcoder.com/acm/contest/52/K 题意: 给定n个点,每个点有自己的权值, 然后让你添加n-1条边,使其边权和最大, 边权的定义是两点的点权和 ...

  4. tiles介绍

    主要目的是为了将复数的jsp页面作为一个的页面的部分机能,然后用来组合成一个最终表示用页面用的,这样的话,便于对页面的各个机能的变更及维护. Tiles使得struts在页面的处理方面多了一种选择.并 ...

  5. 66. No EntityManager with actual transaction available for current thread【从零开始学】

    [从零开始学习Spirng Boot-常见异常汇总] 具体异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: No En ...

  6. [HDU3065]病毒持续侵袭中(AC自动机)

    传送门 AC自动机的又一模板,统计每个字符串在文本中的次数. 所以就不需要vis数组了. ——代码 #include <cstdio> #include <cstring> # ...

  7. msp430项目编程05

    msp430中项目---TFT彩屏显示(续) 1.TFT彩屏工作原理 2.电路原理说明 3.代码(静态显示) 4.代码(动态显示) 5.项目总结 msp430项目编程 msp430入门学习

  8. Back弹出AlertDialog

    package com.pingyijinren.helloworld.activity; import android.content.DialogInterface; import android ...

  9. hdu1072(bfs)

    #include<iostream> #include<queue> #include<cstring> using namespace std; int a[10 ...

  10. 2015轻院校赛 D 社交网络(排列组合)

    http://acm.zznu.edu.cn/problem.php?id=1964 题目描述 输入 输出 样例输入 2 2 1 0 1 1 0 3 1 0 1 1 1 0 1 1 1 0 样例输出 ...