title: Python loop through list to get api call in asyncio and save results
body: <p>I don't fully understand how asyncio and aiohttp work yet.</p>
  
  <p>I am trying to make a bunch of asynchronous api requests from a list of urls and save them as a variable so I can processes them later.</p>
  
  <p>so far I am generating the list which is no problem and setting up the request framework.</p>
  
  <pre><code>urls = []
  for i in range(0,20):
      urls.append('https://api.binance.com/api/v1/klines?symbol={}&amp;interval= 
      {}&amp;limit={}'.format(pairs_list_pairs[i],time_period,
              pull_limit))
  
  import asyncio
  import aiohttp
  
  
  async def request(url):
      async with aiohttp.ClientSession() as session:
          async with session.get(url) as resp:
              return await resp.text()
  
  
  async def main():
      results = await asyncio.gather(
               request(urls[0]),
               request(urls[1]),
      )
      print(len(results))
      print(results)
  
  
  
  loop = asyncio.get_event_loop()
  try:
      loop.run_until_complete(main())
      loop.run_until_complete(loop.shutdown_asyncgens())
  finally:
      loop.close()
  </code></pre>
  
  <p>If I manually type out my requests one by one using indexing (like below), I can make the request. But the problem is that my list has upwards of 100 apis requests that I don't want to type by hand. How can I iterate through my list? Also how can I save my results into a variable? When the script ends it does not save "results" anywhere.</p>
  
  <pre><code>async def main():
      results = await asyncio.gather(
               request(urls[0]),
               request(urls[1]),
      )
      print(len(results))
      print(results)
  </code></pre>
  
  <p>Below are some sample urls to replicate the code:</p>
  
  <pre><code>[
   'https://api.binance.com/api/v1/klines?symbol=ETHBTC&amp;interval=15m&amp;limit=1',
   'https://api.binance.com/api/v1/klines?symbol=LTCBTC&amp;interval=15m&amp;limit=1',
   'https://api.binance.com/api/v1/klines?symbol=BNBBTC&amp;interval=15m&amp;limit=1',
   'https://api.binance.com/api/v1/klines?symbol=NEOBTC&amp;interval=15m&amp;limit=1',
  ]
  </code></pre>