title: How do I reverse an itertools.chain object?
body: <p>My function creates a chain of generators:</p>
  
  <pre><code>def bar(num):
      import itertools
      some_sequence = (x*1.5 for x in range(num))
      some_other_sequence = (x*2.6 for x in range(num))
      chained = itertools.chain(some_sequence, some_other_sequence)
      return chained
  </code></pre>
  
  <p>My function sometimes needs to return <code>chained</code> in reversed order. Conceptually, the following is what I would like to be able to do:</p>
  
  <pre><code>if num &lt; 0:
      return reversed(chained)
  return chained
  </code></pre>
  
  <p>Unfortunately:</p>
  
  <pre><code>&gt;&gt;&gt; reversed(chained)
  TypeError: argument to reversed() must be a sequence
  </code></pre>
  
  <p>What are my options?</p>
  
  <p>This is in some realtime graphic rendering code so I don't want to make it too complicated/slow.</p>
  
  <p><strong>EDIT</strong>:
  When I first posed this question I hadn't thought about the reversibility of generators. As many have pointed out, generators can't be reversed.</p>
  
  <p>I do in fact want to reverse the flattened contents of the chain; not just the order of the generators.</p>
  
  <p>Based on the responses, there is no single call I can use to reverse an itertools.chain, so I think the only solution here is to use a list, at least for the reverse case, and perhaps for both.</p>