Python3:operator模块中的itemgetter()函数
2017-09-01 11:14
621 查看
Python3:operator模块中的itemgetter()函数
转载请注明作者和出处:http://blog.csdn.net/u011475210
操作系统:WINDOWS 10
软件版本:python-3.6.2-amd64
编 者:WordZzzz
和之前一样,本渣渣先贴出来python中help的帮助信息:
operator.itemgetter函数
operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子。
要注意,operator.itemgetter函数获取的不是值,而是定义了一个函数,通过该函数作用到对象上才能获取值。
系列教程持续发布中,欢迎订阅、关注、收藏、评论、点赞哦~~( ̄▽ ̄~)~
完的汪(∪。∪)。。。zzz
转载请注明作者和出处:http://blog.csdn.net/u011475210
操作系统:WINDOWS 10
软件版本:python-3.6.2-amd64
编 者:WordZzzz
和之前一样,本渣渣先贴出来python中help的帮助信息:
>>> import operator >>> help(operator.itemgetter) Help on class itemgetter in module operator: class itemgetter(builtins.object) | itemgetter(item, ...) --> itemgetter object | | Return a callable object that fetches the given item(s) from its operand. | After f = itemgetter(2), the call f(r) returns r[2]. | After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]) | | Methods defined here: | | __call__(self, /, *args, **kwargs) | Call self as a function. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | __reduce__(...) | Return state information for pickling | | __repr__(self, /) | Return repr(self).
operator.itemgetter函数
operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子。
a = [1,2,3] >>> b=operator.itemgetter(1) //定义函数b,获取对象的第1个域的值 >>> b(a) 2 >>> b=operator.itemgetter(1,0) //定义函数b,获取对象的第1个域和第0个的值 >>> b(a) (2, 1)
要注意,operator.itemgetter函数获取的不是值,而是定义了一个函数,通过该函数作用到对象上才能获取值。
系列教程持续发布中,欢迎订阅、关注、收藏、评论、点赞哦~~( ̄▽ ̄~)~
完的汪(∪。∪)。。。zzz
相关文章推荐
- python排序sorted()与operator.itemgetter()函数
- Python operator.itemgetter函数理解
- Python中的sorted()函数以及operator.itemgetter()函数
- python的operator.itemgetter('click')用于定义获取'click'项的函数
- python的operator.itemgetter('click')用于定义获取'click'项的函数
- python学习 -- operator.itemgetter(), list.sort/sorted 以及lambda函数
- operator.itemgetter函数和字典的item()函数
- python sorted operator.itemgetter
- operator.itemgetter(*items) @ python
- python sorted函数(结合使用lambda和operator.itemgetter()来对字典进行排序)
- 【Python】iteritems()与itemgetter()函数作用
- python——sorted函数、sort函数以及operator.itemgetter的使用
- python中operator.itemgetter
- python中的sorted、iteritems和operator.itemgetter
- Python: sorted,operator.itemgetter的用法
- python3使用operator.itemgetter对字典进行排序
- python operator.itemgetter
- Python中的sorted以及operator.itemgetter的用法
- Python: 字典列表: itemgetter 函数: 根据某个或某几个字典字段来排序列表
- Python学习3-Panel,DataFrame, operator.itemgetter,sorted()