python itertools

python itertools 是迭代器的标准包 以下是他的方法和用法


1、chain 将多个列表迭代,参数是列表


import itertools  
listone = ['a','b','c']  
listtwo = ['11','22','abc']  
for item in  itertools.chain(listone,listtwo):  
    print item
 


2、count 是一个无界的迭代
itertools.count(start,step)只能是数字。。。






3、cycle (列表) 只能是一个列表。。。。。
从列表中取元素,到列表尾后再从头取...


4、ifilter(fun,iterator)返回一个可以让fun返回True的迭代器,




5、imap(fun,iterator)
返回一个迭代器,对iterator中的每个项目调用fun


6.islice的使用
islice()(seq, [start,] stop [, step])
功能:返回迭代器,其中的项目来自 将seq,从start开始,到stop结束,以step步长切割后


7.izip的使用     izip(*iterator)
功能:返回迭代器,项目是元组,元组来自*iterator的组合


8. repeate  repeate(elem [,n])
功能:重复elem n次








官方帮助文件
    count([n]) --> n, n+1, n+2, ...
    cycle(p) --> p0, p1, ... plast, p0, p1, ...
    repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times
    
    Iterators terminating on the shortest input sequence:
    chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... 
    compress(data, selectors) --> (d[0] if s[0]), (d[1] if s[1]), ...
    dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails
    groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)
    ifilter(pred, seq) --> elements of seq where pred(elem) is True
    ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False
    islice(seq, [start,] stop [, step]) --> elements from
           seq[start:stop:step]
    imap(fun, p, q, ...) --> fun(p0, q0), fun(p1, q1), ...
    starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...
    tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n
    takewhile(pred, seq) --> seq[0], seq[1], until pred fails
    izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
    izip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
    
    Combinatoric generators:
    product(p, q, ... [repeat=1]) --> cartesian product
    permutations(p[, r])
    combinations(p, r)
    combinations_with_replacement(p, r)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值