Skip to content

Instantly share code, notes, and snippets.

@awg01
Created June 26, 2019 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awg01/68a269277d4deb7eb1d8166f4506ca72 to your computer and use it in GitHub Desktop.
Save awg01/68a269277d4deb7eb1d8166f4506ca72 to your computer and use it in GitHub Desktop.
I want to whether the cityname(from csv file) is present in given sentence.
import csv
from re import search
#example_sent2 = "Sunset is the time of day when our sky meets the outer space solar winds. There are blue, pink, and purple swirls, spinning and twisting, like clouds of balloons caught in a whirlwind. The sun moves slowly to hide behind the line of horizon, while the moon races to take its place in prominence atop the night sky. People slow to a crawl, entranced, fully forgetting the deeds that must still be done. There is a coolness, a calmness, when the sun does set..XYZ, Example Exports as my Post Office Box 924 Yavatmal - 445001 INDIA.Ram is a very good student."
pin = []
ct = []
#for loading csv file into list
with open('pincode_final.csv',"r") as csvfile:
csv_f = csv.reader(csvfile)
for row in csv_f:
pin.append(row[0]) #for future use
ct.append(row[1]) #etc for all columns
print(len(ct))
matches = []
#example_sent2 = "Anusandhan Bhawan, C-56/1, Sector-62,Allahabad - 201307 Uttar Pradesh (India)"
example_sent2 = "Anusandhan Bhawan, C-56/1, Sector-62, Bhadohi - 201307 Uttar Pradesh (India)"
#print(random.choice(ct))
for city in ct:
if search(r'\b{}\b'.format(city), example_sent2):
print(search(r'\b{}\b'.format(city), example_sent2))
break
#print(matches)
@awg01
Copy link
Author

awg01 commented Jun 26, 2019

https://www.kaggle.com/sahilgandhi94/indian-pincodes/downloads/indian-pincodes.zip/1
Here's the csv file.
The problem is I'm able to search upto 1981 records but after I am getting error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment