title: Python aggregate on a generator
body: <p>I have a generator that returns a list in each iteration. Each element of the list could be either 0 or 1. I want to count the total number of elements returned (including both 0 and 1) and the total number of 1 returned. I tried to implement this using reduce function like this :</p>
  
  <pre>
  t = reduce( (lambda x,y:(y[0]+1,y[1]+x)), gen_fn(), (0,0))
  </pre>
  
  <p>gen_fn() above is the generator that returns part of the list in each yield statement. I wanted to implement it by initializing with a tuple (0,0) for count. Given that the elements returned from generator are following :</p>
  
  <pre>
  [0, 1, 1, 0, 1]
  </pre>
  
  <p>My expected output for t is (5,3). But my code is failing with this error message :</p>
  
  <pre>
  TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
  </pre>
  
  <p>Can anybody help me identify the problem? My lack of experience with reduce and lambda functions is preventing me from figuring out what I am doing wrong. Thanks in advance.</p>