title: Apply a condition only once in a recursion
body: <p>I want to apply a condition inside a resursion only once. My data structure looks as follows</p>
  <pre><code>stages = {&quot;stage_1&quot;: False, &quot;stage_2&quot;:False, &quot;stage_3&quot;:False,&quot;state_4&quot;: False}
  </code></pre>
  <p>I want to pick any stage randomly from it and change the status to True. But when total number of true stage is 3 I want to randomly change a True stage to False. But only once. Then it should continue to turn stages in to True. When all 4 stages are true. The recursion process stops.
  How can I do that ?
  I have tried the following code. but it is not complete.</p>
  <pre><code>def process(stages):
      all_stages = [stage for stage, status in stages.items() if status == False]
      if len(all_stages) !=0:
          print(all_stages)
          select_ = random.choice(all_stages)
          print(&quot;\tselected stage: &quot;,select_)
          
          stages[select_] = True
          process(stages)
      else:
          print(&quot;Done&quot;)
          print(stages)
  
  process(stages)
  </code></pre>
  <p>This works without adding that extra condition. I have tried the following one. But that does not work</p>
  <pre><code>def process(stages):
      all_stages = [stage for stage, status in stages.items() if status == False]
      if len(all_stages) !=0:
          print(all_stages)
          select_ = random.choice(all_stages)
          print(&quot;\tselected stage: &quot;,select_)
          
          stages[select_] = True
  
          if len(all_stages) == 1:
              select_ = random.choice([stage for stage, status in stages.items() if status == True])
              stages[select_] = False
          process(stages)
      else:
          print(&quot;Done&quot;)
          print(stages)
  
  process(stages)
  </code></pre>