7
我经常写代码,如:平凡函子
sorted(some_dict.items(), key=lambda x: x[1])
sorted(list_of_dicts, key=lambda x: x['age'])
map(lambda x: x.name, rows)
,我还想写
def attr_f(field):
return lambda x: getattr(x, field)
def idx_f(field):
return lambda x: x[field]
是否有仿创作者一样idx_f和attr_f在Python中,并且它们在使用时比lambda更清晰?
太棒了!我记得使用这些方式,但无法在Google上找到它们。 – Herbert