Last active
April 18, 2017 22:46
-
-
Save dvigne/6a5f4d9722d0d612531af90d7595a5e2 to your computer and use it in GitHub Desktop.
Search Through CSV File For Criteria Given In A Text File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import sys | |
inputFile = open(sys.argv[1], 'r') | |
searchCriteria = open(sys.argv[2], 'r') | |
csvContents = inputFile.read() | |
searchContents = searchCriteria.read() | |
csvArray = csvContents.split(',') | |
searchArray = searchContents.split() | |
count = 0 | |
found = {} | |
print("\nSearch Analysis: \n") | |
for x in range(0,len(searchArray)): | |
for y in range(0,len(csvArray)): | |
if(searchArray[x] == csvArray[y]): | |
print("\t" + searchArray[x] + " => " + csvArray[y+1] + " Found!") | |
found[searchArray[x]] = csvArray[y+1] | |
count += 1 | |
print("\nExportable List: \n") | |
for x in range(0,len(searchArray)): | |
try: | |
print("\t" + found[searchArray[x]]) | |
except: | |
print("\tNA"); | |
print("\nTotal Occurences Found: " + str(count) + "/" + str(len(searchArray))) | |
print("\nCountries Not Found: \n") | |
notFound = list(set(searchArray) - set(found)) | |
for x in range(0, len(notFound)): | |
print("\t" + notFound[x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment