Python use 2 lists in 1 loop -


i have below code has list r3000, list of links save html.

is possible save files different names using separate list?

for example, r3000 include link ('http://research.investors.com/quotes/nyse-agilent-technologies-inc-a.htm?fromsearch=1') have list called r3000sym ['a','','',...]. file saved a.html.

import time import urllib2 urllib2 import urlopen  r3000 = ['http://research.investors.com/quotes/nyse-agilent-technologies-inc-a.htm?fromsearch=1',          'http://research.investors.com/quotes/nyse-alcoa-inc-aa.htm?fromsearch=1',          'http://research.investors.com/quotes/nasdaq-american-airlines-group-aal.htm?fromsearch=1',          'http://research.investors.com/quotes/amex-altisource-asset-mgmt-aamc.htm?fromsearch=1',          'http://research.investors.com/quotes/nyse-aarons-inc-aan.htm?fromsearch=1',          'http://research.investors.com/quotes/nasdaq-applied-optoelectronics-aaoi.htm?fromsearch=1',          'http://research.investors.com/quotes/nasdaq-a-a-o-n-inc-aaon.htm?fromsearch=1',          'http://research.investors.com/quotes/nyse-advance-auto-parts-inc-aap.htm?fromsearch=1']  def yahookeystats(stock):     try:         site= stock         hdr = {'user-agent': 'mozilla/5.0'}         req = urllib2.request(site,headers=hdr)         page = urllib2.urlopen(req).read()           datafile = 'a.html'         f = open(datafile,'a')         f.write(page)         f.close()          print 'done',stock      except exception,e:         print str(e)   eachstock in r3000:     yahookeystats(eachstock) 

itertools looking for:

import itertools it1,it2 in itertools.izip(list1,list2):     print(it1,it2) 

zip takes 2 lists , makes tupled list out of them, itertools allows iterate @ same time.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

oracle - Changing start date for system jobs related to automatic statistics collections in 11g -