title: Use a generator within a while loop to blit text onto the screen
body: <p>I have a class that initializes a population of the same word in different variations then over time rearranges the letters into the desired word. In pygame I'm trying to have the current word be displayed onto the screen then change depending on what variation the class is on in real time. The problem I'm facing is being able to call the class and update the screen at the same time.</p>
  
  <p>I was told that I should use a generator and yield the variation and then enter back into the main loop, however this does not work since my <code>Population</code> class does all of the work within a while loop inside of it's <code>__init__</code>.</p>
  
  <p>How could I yield the current variation that I want to change the text being blit onto the screen within the main loop? </p>
  
  <p>code:</p>
  
  <pre><code>class Population:
      def __init__(self, size):
          ...
          while variation.fitness &lt; len(target): # unknown amount of variations
              self.selection() # restarts selection process
  ...
  pg.init()
  top = ''
  ...
  while not done:
      ...
      if event.key == pg.K_RETURN:
          Population(1000)
          top = # I want to make this variable be the current variation within Popualtion
      ...
      top_sentence = font.render((top), 1, pg.Color('blue'))
      screen.blit(top_sentence, (400,400))
  
  </code></pre>