直接上例子:

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的更多相关文章

  1. python中operator.itemgetter函数

    operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. k = [,,] b = ) print(b(k)) #输 ...

  2. Python的operator.itemgetter函数和sorted函数

    写这篇文章的目的是之前在<机器学习实战>用Python3实现KNN算法时用到的几个函数不太懂, 地址: 1- https://github.com/hitergelei/Self-Lear ...

  3. python的operator.itemgetter('click')用于定义获取'click'项的函数

    python的排序参见文章http://blog.csdn.net/longshenlmj/article/details/12747195 这里介绍 import operator模块 operat ...

  4. python学习 -- operator.itemgetter(), list.sort/sorted 以及lambda函数

    Python 中有非常方便高效的排序函数,下面主要介绍如何sort/sorted对list,dict进行排序. 1. 用list.sort /sorted 对list of tuples中第二个值进行 ...

  5. Python中的sorted函数以及operator.itemgetter函数 【转载】

    operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2 ...

  6. Python中的sorted函数以及operator.itemgetter函数

    operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2 ...

  7. 关于python中的operator.itemgetter()函数的用法

    1. operator.itemgetter(num)函数 表示对对象的第num维数据进行操作获取. >>>import operator >>>a = [1, 2 ...

  8. python中的operator.itemgetter函数

    operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号.看下面的例子 a = [,,] >>> b=) ...

  9. Python中使用operator模块实现对象的多级排序

    Python中使用operator模块实现对象的多级排序 今天碰到一个小的排序问题,需要按嵌套对象的多个属性来排序,于是发现了Python里的operator模块和sorted函数组合可以实现这个功能 ...

随机推荐

  1. Linux后台开发常用工具

    内存分析工具valgrind valgrind辅助工具qcachegrind 可视化查看valgrind结果 淘宝DBA团队发布的监控脚本,使用perl开发,可以完成对linux系统和MySql相关指 ...

  2. linux下查看系统进程占用的句柄数

    ---查看系统默认的最大文件句柄数,系统默认是1024 # ulimit -n 1024 ----查看当前进程打开了多少句柄数 # lsof -n|awk '{print $2}'|sort|uniq ...

  3. html中select标签获取选中value和text

    $("#id").find("option:selected").text(); //获取Select选择的Text$("#id").val ...

  4. Hibernate中get和load的区别

    get获取的对象立即执行sql查询数据库中当前实体表中的数据,如果外键关联的其他实体表如果配置了懒加载关闭,则也会查询出外键关联的其他实体表中的数据,否则外键关联的其他实体表则以代理对象表示(称其为代 ...

  5. RAC_Oracle集群服务安装Grid Infrastructure(案例)

    2015-01-24 Created By BaoXinjian Thanks and Regards

  6. DBA_Oracle Erp R12安装虚拟机镜像IP修正(案例)

    2014-07-12 Created By BaoXinjian

  7. Web Penetration Testing 渗透 通信信息安全

    参考 http://download.csdn.net/detail/jason571/8146587 一.操作系统原理,JavaScript,http/https的运行原理,Ajax,SQL等技术基 ...

  8. Win8下修改任務欄的資源管理器默認打開位置

    不能像win7一樣右鍵屬性改了,但還是有辦法的. 新建一個文件夾,建立快捷方式,右鍵快捷方式,將目標改為%windir%\explorer.exe /n,/e,D:\Desktop 然後將該快捷方式拖 ...

  9. SSH学习笔记目录

    1.Spring_2000_Spring_Hibernate_HibernateTemplate

  10. 学习“要件审判九步法”,正确处理五个关系 z

    学习“要件审判九步法”,正确处理五个关系 2015-06-29 07:39:07 | 来源:人民法院报第二版 | 作者:阮丹军 “要件审判九步法”,是邹碧华法官总结审判和审判管理双重经验后的心血之作, ...