operator, itertools
Posted amber-liu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了operator, itertools相关的知识,希望对你有一定的参考价值。
import operator
import itertools
info_list = [ {‘name‘: ‘Quinn‘, ‘age‘: 50}, {‘name‘: ‘Ryan‘, ‘age‘: 18}, {‘name‘: ‘May‘, ‘age‘: 30} ] new_list = sorted(info_list, key=operator.itemgetter(‘age‘)) print(new_list) # 同理, 如果对属性排序, 可以用sorted(obj_list, operator.attrgetter(‘attribute‘)) # [{‘name‘: ‘Ryan‘, ‘age‘: 18}, {‘name‘: ‘May‘, ‘age‘: 30}, {‘name‘: ‘Quinn‘, ‘age‘: 50}] a = [1, 5, 9, 2] b = [7, 77, 5, 8] print(itertools.chain(a, b)) # <itertools.chain object at 0x00000088F43454E0> print(list(itertools.chain(a, b))) # [1, 5, 9, 2, 7, 77, 5, 8]
# 重复操作的判断问题 # 可以利用redis.setnx 返回结果(True, False) 来加锁, 如果为False ,则证明当前已操作(已经设置过值了,但是需要时间), 提示勿重复操作
以上是关于operator, itertools的主要内容,如果未能解决你的问题,请参考以下文章
Kotlin学习之旅解决错误:kotlin.NotImplementedError: An operation is not implemented: Not yet implemented(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
svn报错cleanup failed–previous operation has not finished; run cleanup if it was interrupted的解决办法(代码片段