码迷,mamicode.com
首页 > 编程语言 > 详细

python中operator.itemgetter

时间:2015-09-18 20:28:01      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

直接上例子:

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

标签:

原文地址:http://www.cnblogs.com/nerrissa/p/4820175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!