how can I create word count output in python just by using reduce function?
问题 I have the following list of tuples: [('a', 1), ('a', 1), ('b', 1), ('c',1), ('a', 1), ('c', 1)] I would like to know if I can utilize python's reduce function to aggregate them and produce the following output : [('a', 3), ('b', 1), ('c', 2)] Or if there are other ways, I would like to know as well (loop is fine) 回答1: It seems difficult to achieve using reduce , because if both tuples that you "reduce" don't bear the same letter, you cannot compute the result. How to reduce ('a',1) and ('b'