Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pymongo import MongoClient
- listState=[]
- listZip=[]
- listStateZip=[]
- listCity=[]
- listCityStateZip=[]
- #Assume we have successfully connected to the database
- for a in listState:
- listZip = db.listings.distinct('address.zip', {'address.state': a})
- for b in listZip:
- tempA = {}
- tempA['state'] = a
- tempA['zip'] = b
- listStateZip.append(tempA)
- for a in listStateZip:
- listCity = db.listings.distinct('address.city',{'address.zip':a['zip']})
- for b in listCity:
- tempB = {}
- tempB['city'] = b
- tempB['state'] = a['state']
- tempB['zip'] = a['zip']
- tempB['cityStateZip'] = b + ', ' + a['state'] + ' ' + a['zip']
- listCityStateZip.append(tempB)
Add Comment
Please, Sign In to add comment