title: Making async for loops in Python
body: <p>The following code outputs as follows:</p>
  
  <pre><code>1 sec delay, print "1", 
  1 sec delay, print "2", 
  1 sec delay, print "1", 
  1 sec delay, print "2"
  </code></pre>
  
  <p>How can it be modified to run like this:</p>
  
  <pre><code>1 sec delay, print "1", print "1",
  1 sec delay, print "2", print "2"
  </code></pre>
  
  <p>I would like it to run so that both instances of the for loop begin executing at the same time. As each instance executes, they will encounter the first() function at the same time, then the second() function at the same time, thus printing in the order mentioned above.</p>
  
  <p>Code:</p>
  
  <pre><code>import asyncio
  
  async def first():
      await asyncio.sleep(1)
      return "1"
  
  async def second():
      await asyncio.sleep(1)
      return "2"
  
  async def main():     
      for i in range(2):
        result = await first()
        print(result)
        result2 = await second()
        print(result2)
  
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(main())
  </code></pre>