2017-12-27 189 views

回答

2

lambda它只是一个函数。并且map将在列表中的每个元素中应用该函数。 reduce将根据该函数将列表设置为单个值。

此操作描述一个小例子,

In [2]: res 
Out[2]: 
[{'articles': 124, 'other': 234}, 
{'articles': 124, 'other': 234}, 
{'articles': 124, 'other': 234}] 

In [3]: map(lambda r: r['articles'], res) 
Out[3]: [124, 124, 124] 

In [4]: reduce(lambda x,y:x+y,[124, 124, 124]) 
Out[4]: 372 

希望你能理解这一点,