gmo*_*oss 3 python closures cython
我有一些代码要移植到 Cython,其中有一行类似
my_list.sort(key=lambda x: x.attr[item])
Run Code Online (Sandbox Code Playgroud)
有没有一种很好的Pythonic方法来避免使用itemgetter和attrgetter的某种组合来关闭?
关键是使用该包functional:
from functional import compose
from operator import attrgetter, itemgetter
my_list.sort(key=compose(itemgetter(item), attrgetter('attr')))
Run Code Online (Sandbox Code Playgroud)