Pytho provides a built-in function for this, zip:
for dir, stock, in zip(dirs, stocks)
Demo:
>>> a = ["cat", "dogs"]
>>> b = ["http://cat-service.com", "http://dogs-care.com"]
>>> for animal, site in zip(a, b):
print(animal, site)
cat http://cat-service.com
dogs http://dogs-care.com
See, It's not hard, right? Python makes our life easier! :)
Alternative: If performance really matters, use itertools.izip.
Update
Turns out the answer above is not what the OP was asking. Well, same as Steve, I'd use a dictionary for this:
stock_dict = dict(stock)
urls = [stock_dict.get(file, "Not found") for file in dirs]
Demo:
We assume there are 3 files in the directory, two of them are listed.
>>> stock = [("fileName1","url1"), ("fileName2","url2")]
>>> stock_dict = dict(stock)
>>> dirs = ["fileName1", "fileName2", "fileName3"]
>>> urls = [stock_dict.get(file, "Not found") for file in dirs]
>>> urls
['url1', 'url2', 'Not found']
Hope this helps!
get each url? Are you going to make a web request?