title: How to take first element from iterator/generator and put it back in Python?
body: <p>I would like to take first element from iterator, analyse it, then put it back and work with iterator as if it was not touched.</p>
  
  <p>For now I wrote:</p>
  
  <pre><code>def prepend_iterator(element, it):
      yield element
      for element in it:
          yield element
  
  
  def peek_first(it):
      first_element = next(it)
      it = prepend_iterator(first_element, it)
      return first_element, it
  
  first_element, it = peek_first(it)
  
  analyse(first_element)
  
  continue_work(it)
  </code></pre>
  
  <p>it is possible to write better/shorter?</p>