直接上例子:

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. java命令行HPROF Profiler

    The HPROF Profiler The Heap and CPU Profiling Agent (HPROF)是JAVA2 SDK自带的一个简单的profiler代理,它通过与Java Vir ...

  2. ScalaTour 2.函数

    /** * 1. case class与模式匹配 */ object TestFunction extends App{ def value(expr:Expr): Int = expr match ...

  3. 内存修改console

    #include <stdio.h> #include <windows.h> #include <winuser.h> int main() { int cur_ ...

  4. C# 通过委托控制进度条以及多线程更新控件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. 最大期望算法 Expectation Maximization概念

    在统计计算中,最大期望(EM,Expectation–Maximization)算法是在概率(probabilistic)模型中寻找参数最大似然估计的算法,其中概率模型依赖于无法观测的隐藏变量(Lat ...

  6. POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题

    在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...

  7. JavaScript: bind apply call

    var foo = function(age,sex){ console.log(this.name,age,sex); }; //call将改变函数运行的context foo.call({name ...

  8. struts (二)

    1.运行流程 client --->tomcat  ---> webapp  -->web.xml --->filter -->struts.xml ---->na ...

  9. Oracle中常用操作

    查看表中的字段名和类型 SELECT column_name,DATA_TYPE FROM cols WHERE TABLE_NAME=upper('tableName') ORDER BY COLU ...

  10. cvs 用法

    CVS使用指南 1 概念 CVS是Client/Server结构的并行版本控制系统. 资源库(repository) 存在于服务器上,所有版本的数据仓库.可以把它想象成一个数据库服务器. 模块 (mo ...