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函数组合可以实现这个功能 ...
随机推荐
- 水晶报表(web)表格信息展示
一.环境安装 开发工具使用VS2010+SAP Crystal Reports13_0+.NETformwork4.0 因为vs2010已经不再集成水晶报表,所以需要我们去找合适的版本下载http:/ ...
- Source insight 3572版本安装及An invalid source insight serial number was detected解决方法
Source insight有最新版3572.3.50.0076 下载连接:http://www.sourceinsight.com/down35.html, http://www.sourcei ...
- Ant -- Another Neat Tool
最早用来构建著名的Tomcat,可以看成是一个Java版本的Make.也正因为使用了Java,Ant是跨平台的. Ant有一个构建脚本build.xml <?xml version = ...
- OAF_架构MVC系列3 - View的概述(概念)
2014-06-18 Created By BaoXinjian
- POJ_1287_mst
Networking Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6432 Accepted: 3488 Descri ...
- 网页地图map
<map name="map"> <area shape="rect" coords="75,75,99,99" nohr ...
- python实现字体闪图
!/usr/bin/env python from future import print_function import os.path import sys from optparse impor ...
- JAVA用户数据输入
数据输入 首先需要导入扫描仪 然后声明扫描仪 输出输入提示 接收用户数据的数据 输出用户数据的数据 实例: import java.util.Scanner; //导入扫描仪 public class ...
- sphinx 全文搜索引擎安装与配置
sphinx 全文搜索引擎 sphinx的安装与配置 ------------------------------------------------------------------------- ...
- rails中两种回滚-reversible和revert区别
1 通常迁移内容写在change方法中 ,但是有些迁移内容不能自动通过执行rake:rollback回滚, 所以在迁移文件里要使用 reversible 方法,告诉rails如何回滚例如下面 # co ...