user6727195 user6727195 - 9 months ago 37
JSON Question

Inserting 2 lists into a URL

I have 2 lists like this:

Type = ['Homeless+Shelter','Food+Pantry','Seniors']
Where = ['55410','55414','54669']

And I would like to add them to a URL to create a search to use an API. Here is what I have:

for elem in Type:
url = ''PUBLISHER_KEY'&rpp=50' % (elem)
urllib.urlretreieve(url, 'CityGrid_Search.json)

The URL is going to an API then saving the data as a JSON file. I am inputting the Type list into the url where 'type=%s'
I would like to input the list of zipcodes that correspond to the word in the Type list where . This code works for iterating through Type, but I have to manually change the zipcode in the URL to the corresponding word. Is it possible to put list items in two different spots?

Answer Source

Try this code,

Type = ['Homeless+Shelter','Food+Pantry','Seniors']
Where = ['55410','55414','54669']


for typeObj, whereObj in zip(Type, Where):
    url = '' % (typeObj, whereObj, PUBLISHER_KEY)
    print url

I think, it'll help you out.