itertools模块速查
学习itertools模块记住这张表就OK了
参考:http://docs.python.org/2/library/itertools.html#module-itertools
Infinite Iterators:
Iterator | Arguments | Results | Example |
---|---|---|---|
count() | start, [step] | start, start+step, start+2*step, ... | count(10) --> 10 11 12 13 14 ... |
cycle() | p | p0, p1, ... plast, p0, p1, ... | cycle('ABCD') --> A B C D A B C D ... |
repeat() | elem [,n] | elem, elem, elem, ... endlessly or up to n times | repeat(10, 3) --> 10 10 10 |
Iterators terminating on the shortest input sequence:
Iterator | Arguments | Results | Example |
---|---|---|---|
chain() | p, q, ... | p0, p1, ... plast, q0, q1, ... | chain('ABC', 'DEF') --> A B C D E F |
compress() | data, selectors | (d[0] if s[0]), (d[1] if s[1]), ... | compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F |
dropwhile() | pred, seq | seq[n], seq[n+1], starting when pred fails | dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 41 |
groupby() | iterable[, keyfunc] | sub-iterators grouped by value of keyfunc(v) | |
ifilter() | pred, seq | elements of seq where pred(elem) is true | ifilter(lambda x: x%2, range(10)) --> 1 3 5 79 |
ifilterfalse() | pred, seq | elements of seq where pred(elem) is false | ifilterfalse(lambda x: x%2, range(10)) --> 02 4 6 8 |
islice() | seq, [start,] stop [, step] | elements from seq[start:stop:step] | islice('ABCDEFG', 2, None) --> C D E F G |
imap() | func, p, q, ... | func(p0, q0), func(p1, q1), ... | imap(pow, (2,3,10), (5,2,3)) --> 32 9 1000 |
starmap() | func, seq | func(*seq[0]), func(*seq[1]), ... | starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 91000 |
tee() | it, n | it1, it2, ... itn splits one iterator into n | |
takewhile() | pred, seq | seq[0], seq[1], until pred fails | takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4 |
izip() | p, q, ... | (p[0], q[0]), (p[1], q[1]), ... | izip('ABCD', 'xy') --> Ax By |
izip_longest() | p, q, ... | (p[0], q[0]), (p[1], q[1]), ... | izip_longest('ABCD', 'xy', fillvalue='-') -->Ax By C- D- |
Combinatoric generators:
Iterator | Arguments | Results |
---|---|---|
product() | p, q, ... [repeat=1] | cartesian product, equivalent to a nested for-loop |
permutations() | p[, r] | r-length tuples, all possible orderings, no repeated elements |
combinations() | p, r | r-length tuples, in sorted order, no repeated elements |
combinations_with_replacement() | p, r | r-length tuples, in sorted order, with repeated elements |
product('ABCD', repeat=2) | AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD | |
permutations('ABCD', 2) | AB AC AD BA BC BD CA CB CD DA DB DC | |
combinations('ABCD', 2) | AB AC AD BC BD CD | |
combinations_with_replacement('ABCD', 2) | AA AB AC AD BB BC BD CC CD DD |
itertools模块速查的更多相关文章
- .htaccess下Flags速查表
Flags是可选参数,当有多个标志同时出现时,彼此间以逗号分隔. 速查表: RewirteRule 标记 含义 描述 R Redirect 发出一个HTTP重定向 F Forbidden 禁止对URL ...
- Java API 快速速查宝典
Java API 快速速查宝典 作者:明日科技,陈丹丹,李银龙,王国辉 著 出版社:人民邮电出版社 出版时间:2012年5月 Java编程的最基本要素是方法.属性和事件,掌握这些要素,就掌握了解决实际 ...
- Java, C#, Swift语法对比速查表
原文:Java, C#, Swift语法对比速查表 Java 8 C# 6 Swift 变量 类型 变量名; 类型 变量名; var 变量名 : 类型; 变量(类型推断) N/A var 变量名= ...
- 【转】Vim速查表-帮你提高N倍效率
Vim速查表-帮你提高N倍效率 转自:https://www.jianshu.com/p/6aa2e0e39f99 去年上半年开始全面使用linux进行开发和娱乐了,现在已经回不去windows了. ...
- thinkphp5 速查表
本速查表里的类都是think为命名空间的,实例化时省去了 use.用的时候注意. 本速查表里会有四种方法的调用: 公有方法 $class = new Class(); $class->foo ...
- 这可能是AI、机器学习和大数据领域覆盖最全的一份速查表
https://mp.weixin.qq.com/s?__biz=MjM5ODE1NDYyMA==&mid=2653390110&idx=1&sn=b3e5d6e946b719 ...
- Python语法速查:目录
1. 数据类型与内置函数 2. 列表.元组.字典.集合操作 3. 字符串格式化 4. 字符串常用操作 5. 运算符.math模块.表达式 6. 循环与迭代 7. 函数基础 8. 类与对象 9. 函数进 ...
- Python语法速查: 4. 字符串常用操作
返回目录 (1)字符串常用方法 Python3中,字符串全都用Unicode形式,所以省去了很多以前各种转换与声明的麻烦.字符串属于序列,所有序列可用的方法(比如切片等)都可用于字符串. 注意:字符串 ...
- Python系列教程-详细版 | 图文+代码,快速搞定Python编程(附全套速查表)
作者:韩信子@ShowMeAI 教程地址:http://showmeai.tech/article-detail/python-tutorial 声明:版权所有,转载请联系平台与作者并注明出处 引言 ...
随机推荐
- 【开源项目12】Retrofit – Java(Android) 的REST 接口封装类库
Retrofit官网:http://square.github.io/retrofit/ Retrofit 和Java领域的ORM概念类似, ORM把结构化数据转换为Java对象,而Retrofit ...
- 如何将你自己的Python package发布到PyPI上
零.前言 最近做了一个小工具,查询IP或者域名的归属地.做完之后想发布到PyPI上,这样大家就可以通过pip来安装了. 在发布的过程中遇到了一些问题,也学到了很多东西.记录到这篇文章中.希望对大家有所 ...
- 设置eclipse在linux下提示
在Windows下eclipse按alt+/就可以提示,但是在Linux下eclipse的设置不是这样的alt+/为切换输入法,如果要修改于Windows下的一样就需要修改一下快捷键: 点击windo ...
- javaweb学习总结二十六(response对象的用法二 下载文件)
一:浏览器打开服务器上的文件 1:读取服务器上面的资源,如果在web层,可以直接使用servletContext,如果在非web层 可以使用类加载器读取文件 2:向浏览器写数据,实际上是把数据封装到r ...
- IOS 支付宝、微信回调传值给H5网页
这里用是的苹果原生和JS的交互 .有不明白JavaScriptCore框架的可以去网上搜索下这方面的资料很多废话不多说直接上代码 @protocol JSContextDelegate <JSE ...
- ASP.NET 状态的传递和保存
1,HTTP协议是无状态的.服务器不会记住上次给浏览器的处理结果,如果需要上次处理结果(上次状态)就需要浏览器把处理结果值(上次状态)再次给服务器. 2,URL传值:通过URL参数或者通过Form表单 ...
- Table of Contents - MongoDB
Getting Started Installation Installing MongoDB on Windows Installing MongoDB on Linux Introduction ...
- 面对一个“丢失了与用户“签订”的协议的修改”时进行的思考。
对于上图中的gauge,将value与label之间的比例值调整了,调整为1:1.2.这意味着,在新系统中打开老报表,老报表中的这个gauge的value可能会比以前大,二者可能是用户厌恶的效果. 严 ...
- mvc的一些知识点
MVC是微软2009对外公布的第一个开源的表示层框架,这是微软的第一个开源项目, MVC目的不是取代WebFrom开发,只是web开发的另外一种选择 1.MVC设计模式 M:Model 主要是存储或者 ...
- HDU1358:Period
第一次做KMP.还没有理解透. 在自己写一遍时没有让next[0]初始化为-1. 还有就是next应该是c++中的关键字,提交后编译错误. From: http://blog.csdn.net/lib ...