python中operator.itemgetter
直接上例子:
rs= [
... {
... "datetime": "Mon, 31 Aug 2015 23:00:00 GMT",
... "id": 1,
... "name":"a"
... },
... {
... "datetime": "Mon, 31 Aug 2015 23:00:00 GMT",
... "id": 2,
... "name":"b"
... },
... {
... "datetime": "Mon, 31 Aug 2015 23:00:00 GMT",
... "id": 3,
... "name":"c"
... },
... {
... "datetime": "Mon, 31 Aug 2015 23:00:00 GMT",
... "id": 4,
... "name":"d"
... }
... ]
fun = operator.itemgetter('id', 'name')
for key, g in itertools.groupby(rs, fun):
... print key
... print g
...
(1, 'a')
<itertools._grouper object at 0x7f07e9623650>
(2, 'b')
<itertools._grouper object at 0x7f07e96236d0>
(3, 'c')
<itertools._grouper object at 0x7f07e9623650>
python中operator.itemgetter的更多相关文章
- python中operator.itemgetter函数
operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. k = [,,] b = ) print(b(k)) #输 ...
- Python的operator.itemgetter函数和sorted函数
写这篇文章的目的是之前在<机器学习实战>用Python3实现KNN算法时用到的几个函数不太懂, 地址: 1- https://github.com/hitergelei/Self-Lear ...
- python的operator.itemgetter('click')用于定义获取'click'项的函数
python的排序参见文章http://blog.csdn.net/longshenlmj/article/details/12747195 这里介绍 import operator模块 operat ...
- python学习 -- operator.itemgetter(), list.sort/sorted 以及lambda函数
Python 中有非常方便高效的排序函数,下面主要介绍如何sort/sorted对list,dict进行排序. 1. 用list.sort /sorted 对list of tuples中第二个值进行 ...
- Python中的sorted函数以及operator.itemgetter函数 【转载】
operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2 ...
- Python中的sorted函数以及operator.itemgetter函数
operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2 ...
- 关于python中的operator.itemgetter()函数的用法
1. operator.itemgetter(num)函数 表示对对象的第num维数据进行操作获取. >>>import operator >>>a = [1, 2 ...
- python中的operator.itemgetter函数
operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号.看下面的例子 a = [,,] >>> b=) ...
- Python中使用operator模块实现对象的多级排序
Python中使用operator模块实现对象的多级排序 今天碰到一个小的排序问题,需要按嵌套对象的多个属性来排序,于是发现了Python里的operator模块和sorted函数组合可以实现这个功能 ...
随机推荐
- 通过共享用户ID来实现多个应用程序使用同一个进程(一些情况的测试)
从很多方面来看,每个Android 应用程序都存在于它自己的世界之中:• 默认情况下,每个应用程序均运行于它自己的Linux 进程中.当应用程序中的任意代码开始执行时,Android 启动一个进程,而 ...
- 《黄聪:手机移动站SEO优化教程》4、如何实现手机移动网站和PC站点的自主适配
视频地址:http://www.tudou.com/programs/view/v4Hur5vjav4/ 1.自主适配 A:站点自己做好PC与手机之间的适配,以及手机站各个版式之间的适配.当手机用户通 ...
- 如何写出小而清晰的函数?(JS 版)
本文以 JavaScript 为例,介绍了该如何优化函数,使函数清晰易读,且更加高效稳定. 软件的复杂度一直在持续增长.代码质量对于保证应用的可靠性.易扩展性非常重要. 然而,几乎每一个开发者,包括我 ...
- Coding 初级教程(二)——上传已有项目
Coding 初级教程(二)——上传已有项目 [摘要:方针读者 :已具有 Coding.net 的账号. 本文首要先容若何把项目上传到 Coding.net 上. 分两种环境,一种是项目已归入到 gi ...
- Java注解处理器--annotation学习四
Java中的注解(Annotation)是一个很神奇的东西,特别现在有很多Android库都是使用注解的方式来实现的.一直想详细了解一下其中的原理.很有幸阅读到一篇详细解释编写注解处理器的文章.本文的 ...
- java中使用正则表达式
1.用正则表达式分割字符串 Pattern SPLIT2 = Pattern.compile("[,]"); String[] tmpStrings1 = SPLIT2.split ...
- log4j+logback+slf4j+commons-logging的关系与调试
背景 由于现在开源框架日益丰富,好多开源框架使用的日志组件不尽相同.存在着在一个项目中,不同的版本,不同的框架共存.导致日志输出异常混乱.虽然也不至于对系统造成致命伤害,但是明显可以看出,架构 ...
- Async/Await - Best Practices in Asynchronous Programming z
These days there’s a wealth of information about the new async and await support in the Microsoft .N ...
- mongodb 查询使用
> db.jd_58tc_raw.findOne() { "_id" : "2659e4e4caf0504ec4362478e2ed57ca", &quo ...
- spring和springmvc之间的整合
一.springmvc就是运行在spring的环境下,这两者是否需要进行整合,即:是不是要把service .dao . 事务 .和其它框架的整合放在springmvc的配置文件中.这样子在技术层面上 ...