You need a spatial structure to speed up lookup for closest zip code. I willwould approach this problem in two steps:
- Create a point quad tree and add all known zip codes to it. Latitude and longitude can be as used as coordinates of the tree node and zip code as value.
- For every zip entry in your myFile, Queryquery the quad tree for closest zip code.
There are many implementationimplementations of quad tree available as python libraryPython libraries. You can pick one of them.