Guest User

Untitled

a guest
May 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. from pymongo import MongoClient
  2.  
  3. listState=[]
  4. listZip=[]
  5. listStateZip=[]
  6. listCity=[]
  7. listCityStateZip=[]
  8.  
  9. #Assume we have successfully connected to the database
  10. for a in listState:
  11. listZip = db.listings.distinct('address.zip', {'address.state': a})
  12. for b in listZip:
  13. tempA = {}
  14. tempA['state'] = a
  15. tempA['zip'] = b
  16. listStateZip.append(tempA)
  17.  
  18. for a in listStateZip:
  19. listCity = db.listings.distinct('address.city',{'address.zip':a['zip']})
  20. for b in listCity:
  21. tempB = {}
  22. tempB['city'] = b
  23. tempB['state'] = a['state']
  24. tempB['zip'] = a['zip']
  25. tempB['cityStateZip'] = b + ', ' + a['state'] + ' ' + a['zip']
  26. listCityStateZip.append(tempB)
Add Comment
Please, Sign In to add comment