码迷,mamicode.com
首页 > 编程语言 > 详细

python itertools

时间:2017-09-16 13:28:18      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:strong   value   返回值   返回   tool   too   参数   bsp   没有   

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

标签:strong   value   返回值   返回   tool   too   参数   bsp   没有   

原文地址:http://www.cnblogs.com/hustdc/p/7530710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!